Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Extracting lines from a file
Name: bakame Date: August 1, 2003 at 08:47:40 Pacific OS: Solaris CPU/Ram: Intel
Comment:
I want to extract certain lines of a file between separators such as: ------ aaabbbb ------ aaaaa xxxxxx ------ xxxxx
What utility (other than awk or perl) would help me to accomplish this task? Thanks!
Name: LANkrypt0 Date: August 1, 2003 at 13:27:02 Pacific
Reply:
Are you looking to basically get everything in the file EXCEPT the: ------
?
If so are all the ------ the same size?
If not, how are you looking/going to specify which portion you want to extract?
0
Response Number 2
Name: bakame Date: August 2, 2003 at 11:21:05 Pacific
Reply:
Yes, and the separators are all the same size. However, there are 2 or 3 or 4 lines of data that I need between the separators in the file. ex: ------ aaaa bbbb ------ xxxxxxx yyyyyyy zzzzzzz ------- jjjjjjj kkkkkkk ------- llllll llllll llllll
0
Response Number 3
Name: Dlonra Date: August 3, 2003 at 17:14:38 Pacific
Reply:
is this different than excluding the separating lines, aaaa bbbb xxxxxxx yyyyyyy zzzzzzz jjjjjjj ....
0
Response Number 4
Name: FishMonger Date: August 4, 2003 at 08:41:00 Pacific
Reply:
Have you tried grep? I'm on a windows system (without grep) so, I can't test and verify if my systax is correct but this should be close.
grep -v /regex pattern for line seperator/ file.txt
The -v option finds all lines that don't match the pattern.
man page for grep http://unixhelp.ed.ac.uk/CGI/man-cgi?grep
0
Response Number 5
Name: FishMonger Date: August 4, 2003 at 14:11:46 Pacific
Reply:
I ran a couple tests and egrep would be better since it has better support for regex's.
Assuming the line seperator is a row of dashes, this egrep command will extract everything else and send it to a file.
egrep -v '^\-+$' file1.txt > file2.txt
If your line seporator is something else, we'll need to modify the regex.
0
Response Number 6
Name: FishMonger Date: August 4, 2003 at 14:19:22 Pacific
Reply:
After another test I discovered that you don't need to escape the dash in the regex. grep didn't like the dash in the regex but egrep didn't care.
here's the cleaner rexeg: '^-+$'
0
Response Number 7
Name: bakame Date: August 5, 2003 at 09:19:02 Pacific
Reply:
Thanks! However, what should I do if I want to extract only some lines: xxxxxxx yyyyyyy zzzzzzz because the answer you gave me will redirect the content of file1.txt to file2.txt except the separators... and what I am looking for is to be able to extract certain lines but not the whole file.
0
Response Number 8
Name: FishMonger Date: August 5, 2003 at 17:02:24 Pacific
Reply:
Can you convince me that this is not your homework assignment?
0
Response Number 9
Name: bakame Date: August 6, 2003 at 07:11:34 Pacific
Reply:
It is part of my project. However, if you feel unconfortable giving me another hint don't worry I will figure it out!
Summary: I need help in trying to extract information from a file (test.file). This file contains other files, basically a catalog of files. I would like to be able to move or extract each file from (test.fi...
Summary: Hi All, I want to get the first line from a file and write it into another file. Please help. Thanks in advance. Regards, Raj Thanks & Regards, Raj...
Summary: i hv written a shell script which exports data to a file and i want to filter out one particular line from that file and manipulate that line further. ...