remove line 1 and save it....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove line 1 and save it....
# 8  
Old 12-20-2006
awk -F] '{
if(NR != 1){
split($1,a,".")
print a[2]
}
}' 33899.d > 33899.r
# 9  
Old 12-20-2006
Quote:
Originally Posted by anbu23
Code:
sed "1d;s/[^.]*\.\([0-9]*\).*/\1/w newfile" file

it look like ok...but cannot write into newfile. Also, if the txt like this below. Can I just ignore first line and starting grep line two number 1076, 1084, 1092,etc - but the number may not the same every new txt) and write into another txt?

-[------:000001071] REPORT1
-[------:000001076] CD98564
-[------:000001084] CD89992
-[------:000001092] CD00001
.
.
.
# 10  
Old 12-20-2006
If the format of the input file varies above code doesnot work.

To send the output to another file
Code:
sed "1d;s/[^.]*[.:]\([0-9]*\).*/\1/" file > newfile

The above code gives you required output if the separator between two numbers are . or :
You can add any other separator there
# 11  
Old 12-20-2006
Quote:
Originally Posted by anbu23
If the format of the input file varies above code doesnot work.

To send the output to another file
Code:
sed "1d;s/[^.]*[.:]\([0-9]*\).*/\1/" file > newfile

The above code gives you required output if the separator between two numbers are . or :
You can add any other separator there
Thank you.The result look good. Smilie
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