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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting lines

Status
Not open for further replies.

ceduardo

Technical User
Aug 6, 2007
1
FR
Hi

Ive been just introduced to AWK and seems to be a powerfull tool.
My problem is that I have thaousands of files that will be read by different applications, and some of them DO NOT ACCEPT a header that is already written in these files.

How would be a AWK script that should:
1. read diferent files in the same directory
2. remove the first 66 lines of each of these files
3. rename the new files

Thanks in advance

Carlos
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

Carlos said:
1. read diferent files in the same directory
Regular [tt]awk[/tt] implementations can not get the list of files in a directory. You have to use external tool for that.
Carlos said:
2. remove the first 66 lines of each of these files
Regular [tt]awk[/tt] implementations does not modify the files. They have access only to the data loaded into the memory.
Carlos said:
3. rename the new files
Regular [tt]awk[/tt] implementations can not rename a file. You have to use external tool for that.

Assuming [tt]bash[/tt] or [tt]ksh[/tt] shell :
Code:
for f in *; do
  awk 'NR>66' "$f" > "$f.new"
done

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top