Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix code to remove top line

Status
Not open for further replies.

DanAuber

IS-IT--Management
Apr 28, 2000
255
FR
I have a file X

I want to run a line or two of code that picks up X, takes out the first line and then saves X (either back as X or as Y)

Can anyone help ?

dan

Dan Auber
 
There are probably many easier ways, but:

num=`cat X | wc -l`
tail -`expr $num - 1` X > Y

will do it. HTH.
 
Thanks for those guys - they sort of work.

Is there a way of removing a certain number of characters from the start of a file ?

Or removing all characters upto (and including) a certain string ?

dan

Dan Auber
 
Removing all characters upto (and including) a certain string ...

awk '/a certain string/{sub("a certain string","");f=1};f==1' X > Y
 
Thanks for that Ygor - seem to be moving in the right direction - what would the above awk command do if the string was in the file twice ?

Is there any way of doing it by remvoing the first n characters from a file ?

thanks for any help...

Dan Auber
 
Hmm, I see. The awk script will remove characters upto (and including) a certain string but also all instances of a certain string. So I guess you want...

awk -v s="a certain string" '
f==1;
f==0{
if(b=index($0,s)){
sub(s,"");
if(c=substr($0,b))
print c;
f=1
}
}' X > Y

And to remove the first 50 characters ...

tail +51c file1

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top