remove first line from a file and put into another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove first line from a file and put into another file
# 1  
Old 10-05-2009
remove first line from a file and put into another file

I want to remove first line from a file containing 10K + records and want to put that into a new file.

Tried sed '1d' filename>newfile
This is writing all the records into new file.

Can somebody help please?
# 2  
Old 10-05-2009
Code:
# line number 1 from oldfile into newfile
head -1 oldfile > newfile
# lines 2 - end from oldfile to newfile
awk 'NR>1' oldfile > newfile

# 3  
Old 10-05-2009
Code:
sed -n 1p urfile > first_line.file

sed -n '2,$'p urfile > rest_lines.file

# 4  
Old 10-06-2009
Code:
 $ sed -i -e '1w firstline' -e '1d'  filename.

After the execution of above command,

i) 'firstline' file will have only the first line from the content of filename.
ii) 'filename' will have all the lines except first line.
# 5  
Old 10-06-2009
Hi
The following three cases along with contents of the files are given:

---Content of OldFile.txt---
Switch to insert mode: press i
Switch to command mode: press Esc

1. sed -n 1p OldFile.txt > NewFile.txt
--OldFile.txt--
Switch to insert mode: press i
Switch to command mode: press Esc
--NewFile.txt--
Switch to insert mode: press i
2. sed '1d' OldFile.txt > NewFile.txt
--OldFile.txt--
Switch to insert mode: press i
Switch to command mode: press Esc
--NewFile.txt--
Switch to command mode: press Esc
3. sed '1d' OldFile.txt
--OldFile.txt--
Switch to insert mode: press i

Cheers
Sumedha
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove line from file and read file line by line

I have a file output.txt. File looks like this name1 10 name2 2 name3 5 I get a number n and I need to remove all lines which has number (after name) smaller or equal to n number. After that I need to write lines from file and my output must be like this: Output: 'name1 10' Output: 'name2... (1 Reply)
Discussion started by: kubo12312
1 Replies

2. Shell Programming and Scripting

Compare two CSV files and put the difference in third file with line no,field no and diff value.

I am having two csv files i need to compare these files and the output file should have the information of the differences at the field level. For Example, File 1: A,B,C,D,E,F 1,2,3,4,5,6 File 2: A,C,B,D,E,F 1,2,4,5,5,6 out put file: (12 Replies)
Discussion started by: karingulanagara
12 Replies

3. Shell Programming and Scripting

Read value of a file, remove first 2 chars and put this value in a variable

Hi i have need of read a file value with cat command and remove first 2character for example cat /sys/class/rtc/day 0x12 Remove char 12 And put this value in a variable is possible with a script thanks for help (6 Replies)
Discussion started by: enaud
6 Replies

4. Shell Programming and Scripting

Put a # in start of a specific line of a file

Hello Guys Please let me know how to solve the below issue I have a file like below drop table R1416.ABC1 cascade constraints; drop table R1416.ABC2 cascade constraints; drop table R1416.ABC3 cascade constraints; drop table R1416.ABC4 cascade constraints; drop table R1416.ABC5... (7 Replies)
Discussion started by: Pratik4891
7 Replies

5. 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

6. Shell Programming and Scripting

Remove line based on string and put new line with parameter

Hi Folks, I am new to ksh, i have informatica parameter file that i need to update everyday with shell script. i need your help updating this file with new parameters. sample data $$TABLE1_DATE=04-27-2011 $$TABLE2_DATE=04-23-2011 $$TABLE3_DATE=03-19-2011 .......Highligned... (4 Replies)
Discussion started by: victor369
4 Replies

7. Shell Programming and Scripting

read a file in shell and put result in a line

Hi All, I have a to read a file and put the result in one line. The i am reading from contain the data like below. 1 signifies the beging of the new line. (6 Replies)
Discussion started by: lottiem
6 Replies

8. Shell Programming and Scripting

put a semicolon at the end of each line of a file

hi, Consider there is a file containing 200 lines. please let me know which command is to be used to put a semicolon at the end of each line. if no single command is there then how it can be achieved. (1 Reply)
Discussion started by: surjyap
1 Replies
Login or Register to Ask a Question