- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Insert text before the first word in all the l...
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
тАО01-12-2005 10:34 AM
тАО01-12-2005 10:34 AM
I have a file and I want to insert a text say "abcd" before the first word in all the lines of the file without opening the file. For example, the input file is something like
1234 5678 90001
1111 1111 11111
The ouput file should be like
abcd 1234 5678 90001
abcd 1111 1111 11111
Can anyone please help me out in this.
Thanks,
Anand
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2005 10:59 AM
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2005 01:33 PM
тАО01-12-2005 01:33 PM
Re: Insert text before the first word in all the lines of a file
> cat > x
1234 5678 90001
1111 1111 11111
> perl -pe '$_="abcd $_"' x
abcd 1234 5678 90001
abcd 1111 1111 11111
Cheers,
Hein.
(0 points please :-)
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2005 03:17 PM
тАО01-12-2005 03:17 PM
Re: Insert text before the first word in all the lines of a file
:1,$s/^/abcd /
Mic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2005 03:26 PM
тАО01-12-2005 03:26 PM
Re: Insert text before the first word in all the lines of a file
Open the file using vi.
do the following.
:%s/^/word to be inserted/g
regards,
Syam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2005 03:27 PM
тАО01-12-2005 03:27 PM
Re: Insert text before the first word in all the lines of a file
one 1
two 1 two 1
three 1
one 1
two 1
two 1
three 1
hello world
[root@iris ~]# sed 's/^/abcd /' sample
abcd one 1
abcd two 1 two 1
abcd three 1
abcd one 1
abcd two 1
abcd two 1
abcd three 1
abcd hello world
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2005 03:37 AM
тАО01-14-2005 03:37 AM
Re: Insert text before the first word in all the lines of a file
$ perl -i.old -pe 's/^/abcd /' a
$ cat a
abcd 1234 5678 90001
abcd 1111 1111 11111
$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2005 04:30 AM
тАО01-14-2005 04:30 AM