- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to find a particular line and add a new 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
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
06-18-2004 12:51 AM
06-18-2004 12:51 AM
I want to have a solution for this scenario.
I have a file which has an entry #Pankaj only in one line. I have to make a new file whereby this entry should be preserved and next line should be " I am here ". To summarize I have a file f1 which has contents:
abc asdfnas
efg ooeooeo
#Pankaj
dkkd kdkfdjfj dkfdjd
kdkf dfdslf
I have to transform this file to f2 which has contents:
abc asdfnas
efg ooeooeo
#Pankaj
I am here ( new line to be added)
dkkd kdkfdjfj dkfdjd
kdkf dfdslf
Can someone suggest me a easy way out???
Regds,
Pankaj
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2004 01:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2004 01:45 AM
06-18-2004 01:45 AM
Re: How to find a particular line and add a new line
You can use 'sed' also though I personally would use awk solution given above.
sed -e '/#Pankaj/{G;s/$/I am here/;}' text
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2004 07:05 PM
06-18-2004 07:05 PM
Re: How to find a particular line and add a new line
you can do thru this vi editor
#vi f1
abc asdfnas
efg ooeooeo
#Pankaj
dkkd kdkfdjfj dkfdjd
kdkf dfdslf
then edit whatever u want then while saving
in command mode of vi
:w filename(f2)
i think this will do for you
Shankar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2004 12:53 AM
06-19-2004 12:53 AM
Re: How to find a particular line and add a new line
#!/usr/bin/ksh
if [ -a /tmp/newfile.000]
then
rm /tmp/newfile.000
fi
cat filename | while read line
do
grep -q Pankaj $line
r=`echo $?`
echo $line >> /tmp/newfile.000
if [ $r -eq 0 ]
then
echo "I am here" >> /tmp/newfile.000
fi
done
this will place the line right after every line that contains the word "Pankaj".
Hope this helps.
line=`grep -n Pankaj filename|cut -d: -f1`
total_lines_in_file=`cat filename | wc -l`
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2004 11:06 PM
06-20-2004 11:06 PM
Re: How to find a particular line and add a new line
THanx for all the wonderful solutions.
Curt, it would be great if you could explain me the working of solution given by you as thats the one I am planning to implement.
Regds,
Pankaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2004 11:47 PM
06-20-2004 11:47 PM
Re: How to find a particular line and add a new line
It says that if the line is begining with #Pankaj, print it (print $0) to the output and then print "I am here" and goto next line of the output.
It ithe line does not begin with #Pankaj then just print the line. (The last line)
HTH
manish.
(please assign points to Curt and others)