grep data from header of files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep data from header of files
# 1  
Old 09-18-2006
grep data from header of files

Hello
I want to grep data from header of the files . The header conatins data in this format .
# $maint$ test1
# $product$ TTT

I want to store maint name and product name with path of file .
# 2  
Old 09-18-2006
sed "s/^#.*\$\(.*\)\$.*$/\1/" file
# 3  
Old 09-18-2006
i have so many files and files are stored in different directories
# 4  
Old 09-18-2006
if you want to do this on everyfile in a particular directory
store directories in variable

Code:
DIR="/usr/xxx/
...
..."
for d in $DIR
cd "$d"
for file in *
do
   sed "s/^#.*\$\(.*\)\$.*$/\1/" $file
done


or if you want to do on particular files then store files with path name in a variable
Code:
path="/usr/xxx/1.txt
...
..."
for file in $path
do
   sed "s/^#.*\$\(.*\)\$.*$/\1/" $file
done


Last edited by anbu23; 09-18-2006 at 01:55 PM..
# 5  
Old 09-18-2006
I have so many files which are stored in one directory and the file extn is *.exp .

I have to grep from header of the file #maint and # product value .

In your loop i have to specify the file name .
# 6  
Old 09-18-2006
path="/usr/xxx/*.exp
...
..."
# 7  
Old 09-19-2006
My problem is *.exp files are stored in sub-directories .

I have path
PATH="/users/test/daily/"

inside daily there are sub directories which contain *.exp files and i want to grep from every files #maint value and #product value and store in the file
with test.exp name ..

Please can u tell me soultion . thanks in advance
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Pivoting data based on a header field

Hi Team, Could you please help me with the below scenario. I have a file which is in the below format. Zipcode,001,001f,002,002f,003,003f,004,004f,005,005f,006,006f,007,007f 0050, ,0, ,0, ,0, ,1,*,7, ,7, ,7 0060, ,0, ,0, ,7, ,0,*,7, ,0, ,0 Would need the output as below. First field... (1 Reply)
Discussion started by: saj
1 Replies

2. Shell Programming and Scripting

Grep Data Base on Header

HI Guys, File A.txt UID,HD1,HD2,HD3,HD4 1,2,33,44,55 2,10,14,15,16 File B.txt UID HD1 HD4 A.txt B.txt >>>Output.txt UID,HD1,HD4 1,2,55 2,10,16 (11 Replies)
Discussion started by: pareshkp
11 Replies

3. Shell Programming and Scripting

How do I use grep to pull incremental data and send to multiple files?

Hi Everyone, Im currently using the below code to pull data from a large CSV file and put it into smaller files with just the data associated with the number that I "grep". grep 'M053' test.csv > test053.csv Is there a way that I can use grep to run through my file like the example below... (6 Replies)
Discussion started by: TheStruggle
6 Replies

4. UNIX for Dummies Questions & Answers

Using grep to make a header

How would I do the following : Records other than ”ATOM”,”CONNECT”, ”HETATM”, ”TER” and ”END” are considered header records which describe the metadata about the molecule. Use grep to generate the header. I have this chemistry database. On the attachment. But I am not sure how to use... (4 Replies)
Discussion started by: homeylova223
4 Replies

5. Shell Programming and Scripting

Extract header data from one file and combine it with data from another file

Hi, Great minds, I have some files, in fact header files, of CTD profiler, I tried a lot C programming, could not get output as I was expected, because my programming skills are very poor, finally, joined unix forum with the hope that, I may get what I want, from you people, Here I have attached... (17 Replies)
Discussion started by: nex_asp
17 Replies

6. UNIX for Dummies Questions & Answers

Merge all csv files in one folder considering only 1 header row and ignoring header of all others

Friends, I need help with the following in UNIX. Merge all csv files in one folder considering only 1 header row and ignoring header of all other files. FYI - All files are in same format and contains same headers. Thank you (4 Replies)
Discussion started by: Shiny_Roy
4 Replies

7. Shell Programming and Scripting

Averaging Data From Multiple Columns, Using Header if Possible

Hi, I have a file with multiple tab delimited columns and I would like to have the average of each column: Iteration Tree No Lh HMean 1000 1 -78.834717 -78.834717 1100 1 -77.991031 -78.624046 1200 1 -79.416055 -78.761861 1300 1 -79.280494 -78.968099 1400 1 -82.846275 -80.808696 ... (4 Replies)
Discussion started by: mikey11415
4 Replies

8. Programming

to find header in Mp3 file and retrieve data

hi all, In an mp3 file , data is arranged in sequence of header and data ,how to retrieve data between two headers. Is the data between two headers fixed? because as per theory it says 1152 samples will be there , but dont knw how many bits one sample correspond to? it would help if any c... (2 Replies)
Discussion started by: shashi
2 Replies

9. Shell Programming and Scripting

grep files without header and move to new dir

Hi, i have number of files in a directory to be processed. the problem is some of the files does not have a header and the process is giving an error of no header found. example of good file : file1 HDR|20080803233401 record 1 record 2 TRA|2 example of a bad file in the same dir ... (6 Replies)
Discussion started by: sitaldip
6 Replies

10. Shell Programming and Scripting

grep data from files

Hello Pls help me i need script for counting number of fails from file . The file contains number of failuer records . (2 Replies)
Discussion started by: getdpg
2 Replies
Login or Register to Ask a Question