remove line 1 and save it....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove line 1 and save it....
# 1  
Old 12-19-2006
remove line 1 and save it....

Hi,

I have txt file like below:

[0000.0217] report date
[0000.0288] 1234567
[0000.0291] 2345234
[0000.1312] 8976542

How can I skip to read line 1 and grep the number 288, 291 and 1312 and save into another new txt file?
# 2  
Old 12-19-2006
assuming you don't want these numbers ANYWHERE on the line, but rather as a second pair of numbers separated by '.' and enclosed inside the '[]'.

one 'ugly' way (that works for most sed-s):
Code:
sed -n '2,$s/.*288].*/&/p;2,$s/.*291].*/&/p;2,$s/.*1312].*/&/p' happy.txt

the 'saving' part is left as an exercise to the OP.

Last edited by vgersh99; 12-19-2006 at 10:02 PM..
# 3  
Old 12-19-2006
Quote:
Originally Posted by vgersh99
assuming you don't want these numbers ANYWHERE on the line, but rather as a second pair of numbers separated by '.' and enclosed inside the '[]'.

one 'ugly' way (that works for most sed-s):
Code:
sed -n '2,$s/.*288].*/&/p;2,$s/.*291].*/&/p;2,$s/.*1312].*/&/p' happy.txt

the 'saving' part is left as an exercise to the OP.
thank you for the suggestion. However, the number like 288, 291, 1312 is not the same everyday (because of the txt file created from someone and i only need the thesee number). How can I do it?
# 4  
Old 12-19-2006
if you have Python installed and assume only a dot in each line.
Code:
#!/usr/bin/python
f=open("file")
f.readline()
for line in f:
     whereisdot = line.index(".")
     whereisclosebracket = line.index("]")
     print line[whereisdot + 1: whereisclosebracket ]


Last edited by ghostdog74; 12-20-2006 at 02:03 AM..
# 5  
Old 12-20-2006
Quote:
Originally Posted by ghostdog74
if you have Python installed and assume only a dot in each line.
Code:
#!/usr/bin/python
for line in open("file"):
     whereisdot = line.index(".")
     whereisclosebracket = line.index("]")
     print line[whereisdot + 1: whereisclosebracket ]

Sorry, the server haven't Python installed. any suggestion?
and the first line should not be read as well..
# 6  
Old 12-20-2006
try this one

awk 'FNR == 1 {next} match($0 ,("288|291|1312")) {print substr($0,RSTART,RLENGTH)}' File > file1.txt
# 7  
Old 12-20-2006
Code:
sed "1d;s/[^.]*\.\([0-9]*\).*/\1/w newfile" file

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Save line from text in variable

Hi, I wrote a csh script where I want to save in a loop each time a different line from a text file (att_file) in the $name variable. But it seems not to work. att_file looks like: 123123123 345345345 345345345 set name = `head -n $count $att_file | tail -n 1 | awk '{print $1}'` Do... (3 Replies)
Discussion started by: MLImag
3 Replies

2. UNIX for Beginners Questions & Answers

Read line and save fields as variables

Hej guys, I am trying to read a csv file line by line, save it's fields as variables per line so I can use them as parameters and execute stuff. I am new to shell scripting and was just strictly following a tutorial. Somehow my version seems to ignore the loop. Any help? TY! :) #!/bin/bash... (12 Replies)
Discussion started by: Splinter479
12 Replies

3. Shell Programming and Scripting

Remove duplicate lines, sort it and save it as file itself

Hi, all I have a csv file that I would like to remove duplicate lines based on 1st field and sort them by the 1st field. If there are more than 1 line which is same on the 1st field, I want to keep the first line of them and remove the rest. I think I have to use uniq or something, but I still... (8 Replies)
Discussion started by: refrain
8 Replies

4. Shell Programming and Scripting

need to remove 1st line of a file and save the file with same old name

Hi friends, I have a doubt, I am not sure whether it is possible ah nu. I am having a file(sample.txt) which contain 5 lines. I want to remove 1st line in the file and save the file with same old name (sample.txt). For removing 1st line i am using sed 1d filename But dono how to... (3 Replies)
Discussion started by: natraj005
3 Replies

5. Shell Programming and Scripting

find the line starting with a pattern and save a part in variable

Hi i have a file which has mutiple line in it. inside that i have a pattern similar to this /abc/def/hij i want to fine the pattern starting with "/" and get the first word in between the the symbols "/" i.e. "abc" in this case into a variable. thanks in advance (13 Replies)
Discussion started by: kichu
13 Replies

6. Shell Programming and Scripting

Expect, save to file and remove before prompt

I have an Expect script which works very well. It logs into my remote routers and runs some commands and then to the next until finished. I need two things, first I need to save the output to a file from where the log_user 1 begins. expect << EOF set timeout 15 #set var "exit " match_max... (1 Reply)
Discussion started by: numele
1 Replies

7. Shell Programming and Scripting

search a string in a line and save it in a variable

Hi I want to read a file line by line and search for a particular string in each line(say for example string containing @ )and save that string into a variable. Can someone suggest me the way to implement it.I am using K- shell Thanks Ishita (5 Replies)
Discussion started by: Ishita
5 Replies

8. Shell Programming and Scripting

save every line in log file with matched string

i have been doing this script to match every line in a current log file (access_log) with strings that i list from a path (consist of 100 of user's name ex: meggae ).. and then make a directory of every string from the text file (/path/meggae/) --->if it matched.. then print every line from the... (3 Replies)
Discussion started by: meggae
3 Replies
Login or Register to Ask a Question