How can i cut first line of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can i cut first line of a file
# 1  
Old 04-06-2009
How can i cut first line of a file

i want to cut first line of a file and use it.It should remove that line from file content.Plz help me
# 2  
Old 04-06-2009
sed '1d' testfile
Will display the file without the 1st line in testfile.
Ex:
$ cat testfile
this is line 1
this is line 2
this is line 3
this is line 4
this is line 5
$ sed '1d' testfile
this is line 2
this is line 3
this is line 4
this is line 5
# 3  
Old 04-06-2009
Code:
head -1 filename 

or 

sed '1d' filename >newfile

newfile will contain the firstline of the file.

Thanks
NT
# 4  
Old 04-06-2009
Quote:
Originally Posted by arghya_owen
i want to cut first line of a file and use it.It should remove that line from file content.
Code:
{
  IFS= read -r line  ## First line is stored in $line
  cat
} < "$FILE" > tempfile && mv tempfile "$FILE"

printf "first line is '%s'\n" "$line"

# 5  
Old 04-06-2009
more +2 file > newfile
# 6  
Old 04-07-2009
And another one Smilie
Code:
awk 'NR != 1' filename

# 7  
Old 04-07-2009
Quote:
Originally Posted by namishtiwari
head -1 filename
This will display only the first line but the requirement is he wants to display except 1st line...

One more

Code:
tail +2 filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

cut the variable from the line and use it to find the file and read the content of that file

Hi, I am working on one script..I am having files in the below format file 1 (each line is separated with : delimeter) SPLASH:SPLASH:SVN CIB/MCH:MCH:SVN Now I want from file 1 that most left part of the first line will store in... (6 Replies)
Discussion started by: rohit22hamirpur
6 Replies

2. Shell Programming and Scripting

cut certain characters for each line in a file

Hi Everyone, i have a file 1.txt <a><a"" dd>aaaaauweopriuew</f><">!(^)!</aa></ff> <a><a"" dd>bbbbbuweopriuew</f><">!(^*)!</aa></ff> i know i can use perl -p -i -e "s/>aaaaa/aa/g" 1.txt perl -p -i -e "s/>bbbbb/bb/g" 1.txt to acheive only keep the first two characters of the five characters,... (4 Replies)
Discussion started by: jimmy_y
4 Replies

3. Shell Programming and Scripting

Cut line from file till the end

Hi I have a 57 line text file and I want to cut first 6 line assigned it to a veriable and again cut next 6 line assigned to same variable till the time file have left 0 line. Please let me know how I can do in scripting. Thanks Sanjay (6 Replies)
Discussion started by: Sanjay2121
6 Replies

4. Shell Programming and Scripting

Display 3rd line of a file using cut only

Hello, i want to use new line character in cut command i want to display 3rd line of a file using cut only( not by sed or head -tail command) can anyone suggest me ? Regards (12 Replies)
Discussion started by: Deepak Dutt
12 Replies

5. Shell Programming and Scripting

cut the second line in a text file

Hi I have some problem to cut out the second line in a output file and send to a new file it's a #!/bin/bash script 1 something 2 something 3 something and after I cut 1 something 3 something New file 2 something Thanks in advance (7 Replies)
Discussion started by: pelle
7 Replies

6. Shell Programming and Scripting

Help need to cut the first word of a line in text file

Hi All, I would like help with a script which can get rid of the first work of all lines in text file. File 1 The name is Scott. Output : name is Scott ---------- Post updated at 02:38 PM ---------- Previous update was at 02:37 PM ---------- Hi ALL There is typo error in... (3 Replies)
Discussion started by: bubbly
3 Replies

7. Shell Programming and Scripting

how to cut a field of a line in a text file?

Hi, I have text file which contains lines like : a/a/a/a/.project b/b/b/b/b/.project c/c/c/.project d/.project e/e/e/e/.project i want for all lines the last word .project should be removed and the file should look like : a/a/a/a/ b/b/b/b/b/ c/c/c/ .... how to proceed... (7 Replies)
Discussion started by: bhaskar_m
7 Replies

8. Shell Programming and Scripting

how to cut first 3 characters of each line in a file

Hi Friends I have a file like sample1.txt ------------ 10998909.txt 10898990.txt 1898772222.txt 8980000000000.txt I need to take first 3 characters of each line in a file and i need to print it ' like loop 109 108 189 898 (7 Replies)
Discussion started by: kittusri9
7 Replies

9. Shell Programming and Scripting

how to grep a file and cut a corresponding value from the line

i have to grep a file which has contents like /Source/value/valuefile/readme.txt DefaultVersion:=1.7 I have to grep this file with "/Source/value/valuefile/readme.txt" and cut the corresponding value "1.7" from the same line i tried grep and cut but not working. (1 Reply)
Discussion started by: codeman007
1 Replies

10. UNIX for Dummies Questions & Answers

Cut a file from line 5745960?

How would I do this simple task? I have a pretty big file, too big to edit in a text editor. I found the line number I need to start with, 5745960. Now I want to say to Unix, give me every line from 5745960 to the end. It seems pretty easy but I can't figure out a simple way to do it. ... (2 Replies)
Discussion started by: LordJezo
2 Replies
Login or Register to Ask a Question