- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: deleting first line
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 01:26 AM
тАО07-01-2010 01:26 AM
deleting first line
I want to delete first line of a line.Manually i can delete.But i want to do it using script.
Actually our tools team facing some issue with a report file.After report generation, first line will always be some junk texts.Now they are manually opening the file and deleting the first line.Now i want to avoid manual interference.
Please suggest
Regards
himacs
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 01:35 AM
тАО07-01-2010 01:35 AM
Re: deleting first line
sed 1d infile >> outfile
rgs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 01:41 AM
тАО07-01-2010 01:41 AM
Re: deleting first line
Thanks for the reply.Your suggestion worked fine.
But i dont want to create new file with output.The same file i want to modify.
If i give head -1
But what command can be used to delete..
rm or dd ..?
Regards
himacs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 01:47 AM
тАО07-01-2010 01:47 AM
Re: deleting first line
You can add 2 line code in the script ,to filter out the file & to have 1st line first line excluded :
sed '1d' report_file > report_file.tmp
mv report_file.tmp report_file
#------------------------------
Now the report_file is the filtered output with first line deleted.
- You can also do with awk:
awk 'NR !=1' report_file > report_file.tmp
mv report_file.tmp report_file
#------------------------------
Enjoy , Have fun!.
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 01:59 AM
тАО07-01-2010 01:59 AM
Re: deleting first line
> But i dont want to create new file with output.The same file i want to modify.
- To modify the same file check this out:
# Deleting first line from the report_file :
perl -i -ne "print unless 1 .. 1" report_file
Enjoy, Have fun!,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 02:03 AM
тАО07-01-2010 02:03 AM
Re: deleting first line
Place it into e.g. /usr/local/bin, make it executable (chmod a+x del-first-line.sh) and make sure the directory is listed in your PATH environment variable.
(Edit /etc/PATH if necessary.)
#!/bin/sh
for i in "$@"; do
mv "$i" "$i.firstlinejunk"
sed -e '1d' "$i.firstlinejunk" > "$i" && rm "$i.firstlinejunk"
done
Usage: del-first-line.sh
Example:
del-first-line.sh report*.sh
The script can process as many files as you can fit on the command line. You can use standard shell wildcards.
As the script processes each file, it renames the original with the ".firstlinejunk" suffix, then creates a new file using the original name, with the first line removed. Only if the creation of the new file is successful, the original is removed.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 02:04 AM
тАО07-01-2010 02:04 AM
Re: deleting first line
check this example :
http://www.unix.com/shell-programming-scripting/37940-delete-first-line-file-more.html
mikap
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 03:51 AM
тАО07-01-2010 03:51 AM
Re: deleting first line
> But i dont want to create new file with output. The same file i want to modify.
I'd use Perl as Raj suggested but with a tweak to handle multiple file specifications at one time.
In your case you want to delete the first line only and do this for one or more files at once:
# perl -i -ne 'print unless $.==1;close ARGV if eof' file1 file2 file3
Regards!
...JRF...