- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- insert text in the same line after a tab
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
02-24-2004 05:45 AM
02-24-2004 05:45 AM
I have a file which has a single column. I need to enter some text on the same line after a tab. That is I need to create a second column based on some condition.
for example if my first column has a number '1234', I would enter 'abcd' in the same line delimited by a tab.
Can anyone please help me to accomplish this task.
Thanks,
Andy.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2004 05:54 AM
02-24-2004 05:54 AM
Re: insert text in the same line after a tab
for i in `cat "your_file"`
do
if [ $i == "1234" ]
then
echo "$i abcd" >> /tmp/new_file
else
echo $i >> /tmp/new_file
fi
note in statement echo "$i abcd" >> /tmp/new_file, there is tab between $i and abcd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2004 06:04 AM
02-24-2004 06:04 AM
Solutionfor i in `cat "your_file"`
do
if [ $i = "1234" ]
then
echo "$i abcd" >> /tmp/new_file
else
echo $i >> /tmp/new_file
fi
cat /tmp/new_file|sort -u > /tmp/final.txt
done
note in statement echo "$i abcd" >> /tmp/new_file, there is tab between $i and abcd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2004 06:21 AM
02-24-2004 06:21 AM
Re: insert text in the same line after a tab
cat file | sed -e 's/^abc/& def/'
between & and def is your tab or ^I character
or
cat file | awk '/^abc/ {printf("%s\tdef\n",$0);next;}{print;}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2004 06:29 AM
02-24-2004 06:29 AM
Re: insert text in the same line after a tab
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2004 06:55 AM
02-24-2004 06:55 AM
Re: insert text in the same line after a tab
ex -s +"1,$ s/^abc/& def/ | wq" yourfile
Procura,
why not just,
perl -pe 's/^(1234)/$1\tabcd/;' fileName
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2004 07:11 AM
02-24-2004 07:11 AM
Re: insert text in the same line after a tab
My solution entered 4 (random) conditions, but leaves it wide open to add many more without too much hassle
I like generic solutions based on the problem stated.
Enjoy, Have FUN! H.Merijn