- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Help in automatically removing lines.
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
Forums
Discussions
Discussions
Discussions
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
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
03-01-2010 03:24 AM
03-01-2010 03:24 AM
i just want to remove the lines in a file from a particular text to end of the file.
eg: consider a file "test" in that
line no 1
line no 2
line no 3
#new lines
Word1
word2
my requirement is to remove the lines after "#new lines"
Please suggest me on the same.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2010 03:26 AM
03-01-2010 03:26 AM
Re: Help in automatically removing lines.
Forget to mention :
I need one script to automatically read and delete the kines after the particular text.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2010 03:45 AM
03-01-2010 03:45 AM
Re: Help in automatically removing lines.
/#new lines/ {
print $0
exit
}
{print $0}' file > file.new
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2010 04:13 AM
03-01-2010 04:13 AM
Re: Help in automatically removing lines.
Thanks for your response.
Can you brief what this script will do ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2010 04:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2010 04:50 AM
03-01-2010 04:50 AM
Re: Help in automatically removing lines.
One way is:
# sed -n '1,/^#new/p' file
This begins by turning off any printing (the '-n'). If the line number is within the inclusive range of line number one (1) through a line that begins (^) with the string "new", then print the line.
Regards!
...JRF...
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2010 05:05 AM
03-01-2010 05:05 AM
Re: Help in automatically removing lines.
and inversed expression to JRF's sed:
# sed '/new lines/,$d' test
rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2010 12:40 AM
03-02-2010 12:40 AM
Re: Help in automatically removing lines.
in general to delete lines between START END:
sed -n'/^START/,/^END/d' file.in >file.out
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2010 05:02 AM
03-02-2010 05:02 AM
Re: Help in automatically removing lines.
$ cat junk
one
two
three
START
four
five
six
seven
END
eight
nine
ten
$ cat junk | sed '/^START/,/^END/d'
one
two
three
eight
nine
ten
$ cat junk | sed -n '/^START/,/^END/p'
START
four
five
six
seven
END
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2010 06:16 AM
03-02-2010 06:16 AM
Re: Help in automatically removing lines.
echo "head -$(($(grep -n '#new lines' test | awk -F : '{print ($1)}') -1 )) test >> test2" |sh
This will find the line number where pattern #new lines is , then subtract 1 from it and use head to put it in another file test2.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2010 01:58 AM
03-03-2010 01:58 AM
Re: Help in automatically removing lines.
And will also read the whole file, then the first part again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2010 12:43 AM
03-08-2010 12:43 AM
Re: Help in automatically removing lines.
I want to print the previous day date.
Please let me know how can i achieve it.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2010 12:49 AM
03-08-2010 12:49 AM
Re: Help in automatically removing lines.
echo `(export TZ=XYZ+24; date "+%d/%m/%y")`
Horia.
Horia.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2010 12:58 AM
03-08-2010 12:58 AM
Re: Help in automatically removing lines.
Thanks a lot for your response
can you just brief what this command will do ?
Also what will happen at the starting of month. say jan 1. In that case will it display the last year an last month date ?
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2010 01:01 AM
03-08-2010 01:01 AM
Re: Help in automatically removing lines.
>Also what will happen at the starting of month. say jan 1. In that case will it display the last year an last month date ?
Yes, it will work. Will work also on March, 1 showing February 28/29 and so...
Horia.
Horia.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2010 01:08 AM
03-08-2010 01:08 AM
Re: Help in automatically removing lines.
I want to customize the year part of the o/p.
rt now its showing as 07/03/10 , iwant it in 07/03/2010.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2010 02:09 AM
03-08-2010 02:09 AM
Re: Help in automatically removing lines.
Just change %y with %Y
man date should help.
Horia.
Horia.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2010 04:46 AM
03-08-2010 04:46 AM
Re: Help in automatically removing lines.
> I want to customize the year part of the o/p...its showing as 07/03/10 , i want it in 07/03/2010
# perl -MPOSIX -le 'print strftime "%02m/%02d/%Y",localtime(time-(60*60*24))'
...will give you yesterday's date correctly, crossing year boundaries as necessary.
You can change the format of the output just like you would using a simple 'date' command format.
Do *not* be fooled by trying to manipulate your 'TZ' variable by adding or subtracting 24-hours. This works correctly only for UTC (GMT) timezones. Use Perl;
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2010 10:21 PM
03-08-2010 10:21 PM
Re: Help in automatically removing lines.
Can you please explain this?
Horia.
Horia.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 01:18 AM
03-09-2010 01:18 AM
Re: Help in automatically removing lines.
The code in libc only expects to have valid timezones. These are UTC +/- 12 hours.
What you did was:
$ TZ=XYZ+24 date "+%d/%m/%y %Z"
08/03/10 XYZ
This converts to UTC time and adds 24 hours. What if there was a DST transition and you skip or lose a day?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 03:29 AM
03-09-2010 03:29 AM
Re: Help in automatically removing lines.
>This converts to UTC time and adds 24 hours. What if there was a DST transition and you skip or lose a day?
I understand.
>What you did was:
>$ TZ=XYZ+24 date "+%d/%m/%y %Z"
>08/03/10 XYZ
When the timezone is not defined (XYZ), it defaults to UTC/GMT
I found a similar discussion from some years ago:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1074176
James explains that only in Europe (and why) this would work.
Horia.
Horia.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2010 01:06 AM
03-11-2010 01:06 AM
Re: Help in automatically removing lines.
I am confused, :)
GMT+24, PST+24 and XYZ+24 all are giving the same o/p.
Please help me to find the difference b/w these.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2010 04:33 AM
03-11-2010 04:33 AM
Re: Help in automatically removing lines.
> I am confused, :)
As I said in your thread, and as I and others said in the thread Horia referenced, persisting in trying to add or subtract an hour offset to TZ is not always going to work!
The tiny Perl snippet to obtain yesterday's or tomorrow's date (or virtually any date in the past or future by subtracting or adding some number of Epoch seconds) is guaranteed to yield accurate date and time offsets.
Regards!
...JRF...