English 中文(简体)
Grep 数据和产出
原标题:Grep data and output to file

I m 试图从原木档案中提取数据并系统地加以整理。 我有大约9个记录文档,每份大小为100米。

我试图做的是:从每个记录文档中摘取的多个chunks,而对于每个提取的原始数据,我想建立一个新的档案,并将这一抽取的数据节省下来。 每个草坪都有明确的开端点。

基本上,我取得了一些进展,并能够提取我所需要的数据,但是,我在试图说明如何为每个配对的chu建立一个新的档案时,打上了围墙。

由于我环境的制约因素,我无法使用像Sharma或Perl这样的节目。 因此,请不要听途说。

My command thus far:

find Logs 13Sept/Log_00000000*.log -type f -exec 
sed -n  /LRE Starting chunk/,/LRE Ending chunk/p  {} ; | 
grep -v -A1 -B1 "Starting chunk" > Logs 13Sept/Chunks/test.txt

The LRE Starting chunk and LRE Ending chunk are my boundaries. Right now my command works, but it saves all matched chunks to one file (whose size is becoming exessive).

我如何为每种配对建立一个new<>/em>文档,并添加相应的内容? 牢记每个档案都有多个空白处,但不限于每个档案中一个空白处。

最佳回答

Try something like this:

find Logs 13Sept/Log_00000000*.log -type f -print | while read file; do 
sed -n  /LRE Starting chunk/,/LRE Ending chunk/p  "$file" | 
grep -v -A1 -B1 "Starting chunk" > "Logs 13Sept/Chunks/$file.chunk.txt";
done

这套文件收集了结果,每个档案都安装了,然后创建了一个单册。 每份档案中都有空白。

问题回答

或许需要比以下几条方案: 我一刀切。

awk  
    /LRE Ending chunk/ {printing = 0}
    printing {print > "chunk" n ".txt"}
    /LRE Starting chunk/ {printing = 1; n++}
  *.log

也许这样一些?

find Logs 13Sept/Log_00000000*.log -type f -exec 
sed -n  /LRE Starting chunk/,/LRE Ending chunk/{;/LRE .*ing chunk/d;w
 "{}.chunk" ;}  {} ;

该指令使用的是w指令,以便写到一个名称的档案(投入文件)。 chu。 如果不能接受,也许你可以用sh子(c)把 command子通过,把 command子包起来。 (出于某种原因,还禁止打字)

也许你可以使用<代码>csplit进行分批处理,然后将产出档案按草图分类。





相关问题
cygwin file path tab completion not working

How can I set up Cygwin to have tab completion? Actually, I do have it automatically, but it does not seem to complete paths. How do I set it up to complete paths?

cygwin version of idle has erroneous I/O handling

I am using idle (python 2.5) via cygwin on a windows vista machine and when I try to open an already existing .py file I see the full file path /home/aaron/C:/cygwin/home/aaron/script.py on the ...

Trying to get a terminal to work in Emacs

I ve been having a lot of problems with emacs and trying to get the terminal to work with: M-x term I installed cygwin and I fixed up my .emacs to include the paths: (setenv "PATH" (concat "...

Piping Cygwin into a Python program

As a i m new to the whole Piping thing and Python I had recently encountered a problem trying to pipe Cygwin s stdin & stdout into a python program usin Python s subprocess moudle. for example I ...

Unable to chdir() on Git/Cygwin

I installed Git via Cygwin on Windows Server. It works out very well. However there s a small issue that when I clone a repo use the command as following: $git clone git@myserver:project.git I ...

Linux Development C/C++/bash/python on windows-7

Before resorting to stackoverflow, i have spend a lot of times looking for the solutions. I have been a linux-user/developer for few years, now shifting to windows-7. I am looking for seting-up a ...

Cygwin/Git/Gitosis unable to push new repository

I ve recently set up cygwin, git, and gitosis on my Windows Server 2003 box and am having troubles. I ve followed just about every tutorial I can find to the letter, and have confirmed that my git ...

热门标签