![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to Select or cut from the certain filed to the end of the line | grajesh_955 | Shell Programming and Scripting | 5 | 04-10-2008 04:07 AM |
| awk program to select a portion of a line | anju | Shell Programming and Scripting | 3 | 01-11-2008 03:33 AM |
| Need to replace the first word of a line if it occurs again in the next line(shell) | geeko | Shell Programming and Scripting | 1 | 09-25-2007 07:15 AM |
| Select matches between line number and end of file? | Jerrad | Shell Programming and Scripting | 4 | 05-24-2006 04:50 AM |
| awk to select a column from particular line number | mab_arif16 | Shell Programming and Scripting | 4 | 05-08-2006 02:26 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to select line by line in shell
Hi,
This is what the file data.lst contains. aaaaaaaa eeeeeeeeeeeeeeee 4444444 rrrrrrrrrrrrr tttttttttttt bbbbbbbb eeeeeeeeeeeeeeee 7777777 uuuuuuuu eeeeeeeee qqqqqqqq gggggggggggggggg 6666666 oooooooo ppppppppp Here I want to cut the third field and put it in a new file I tried this way echo for i in `cat data.lst` do echo $i | cut -c 30-37 >> newfile.lst done But this doesn't work.Can someone help me. Thanks in advance Last edited by preethgideon; 10-11-2006 at 03:28 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
You need a space ie cut -c 30-37
Also try cat data.lst | awk '{print $3}' > /tmp/newfile |
|
#3
|
|||
|
|||
|
Hey Andrek,
The awk worked.I did't get the first one.Anyways thank you very much. Have a great day.Bye |
|
#4
|
|||
|
|||
|
Hi Andrek,
I have another problem. I have have a similar file this way aaaaaaaa eeeeeeeeeeeeeeee 4444R16 rrrrrrrrrrrrr tttttttttttt bbbbbbbb eeeeeeeeeeeeeeee 7777777 uuuuuuuu eeeeeeeee qqqqqqqq gggggggggggggggg 6666R16 oooooooo ppppppppp In some lines last 3 digits of the third field ends with R16.If it ends with R16 then concatinate to a new file else proceed. Help !! |
|
#5
|
|||
|
|||
|
Python alternative:
Code:
o = open("output","a")
for line in open("input.txt"):
line = line.strip().split()
if line[2].endswith("R16"):
print >>o, ' '.join(line)
o.close()
/home> python test.py aaaaaaaa eeeeeeeeeeeeeeee 4444R16 rrrrrrrrrrrrr tttttttttttt qqqqqqqq gggggggggggggggg 6666R16 oooooooo ppppppppp |
|
#6
|
|||
|
|||
|
I am using vi.Will I be able to use this code ?
Its giving the error for sysntax. |
|
#7
|
|||
|
|||
|
Quote:
Code:
cut -d" " -f3 data.lst > newfile.lst |
|||
| Google The UNIX and Linux Forums |