- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- File Content replacement
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
11-30-2004 04:04 PM
11-30-2004 04:04 PM
...
...
...
SFC_ID,
...
...
I need a command or a perl command to add a "" after the SFC_ID, line.
Maximum points for all correct!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2004 04:29 PM
11-30-2004 04:29 PM
Re: File Content replacement
...
SFC_ID,
...
$ perl -pe 's/(^SFC_ID,$)/\1""/' x
...
SFC_ID,""
...
I use the (xxx) ... \1 construction to allow you to replace it with more elaborate match strings and append "" to whatever matches.
For example: 's/(^\w+_ID,$)/\1""/'
This will append to any line with an _ID token, including SFC_ID.
- the () remebers into \1
- the ^ forces to start looking at Begin of line
- the $ forces the line to end right there.
sprinkle with \s* and remove anchors as required.
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2004 05:21 PM
11-30-2004 05:21 PM
Re: File Content replacement
cat file | sed 's/SFC_ID,/SFC_ID,\"\"/' > file1
mv file1 file
Regards,
Gideon
( who is not sure about the \"\" part)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2004 05:24 PM
11-30-2004 05:24 PM
Re: File Content replacement
Thanks for the solution. I've tested it but when i open the file, there is no "" character strings after the SFC_ID, line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2004 05:33 PM
11-30-2004 05:33 PM
Re: File Content replacement
Well... it worked for me.
Apparently your actual datafile does not match what you included in the topic, and what I describe in the explanation for the match.
There might be trailing spaces. If you want to retain those before the "" then try:
$ perl -pe 's/(^SFC_ID,\s*$)/\1""/' x
or after:
$ perl -pe 's/(^SFC_ID,)/\1""/' x
or gone:
$ perl -pe 's/(^SFC_ID,)\s*$/\1""/' x
Untested!
If it still does not work, then please attach a text file with soem actual sample data.
And... try to read up on 'regular expressions' "a gift for life"
\s is 'whitespace such as blank or tab'
\s* is 'zero or more whitespaces'
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2004 06:08 PM
11-30-2004 06:08 PM
Re: File Content replacement
Please see attached file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2004 02:30 AM
12-01-2004 02:30 AM
SolutionI just saved your attachment to my pc.
Tossed it over to a drive on a (tru64) unix box as tmp.dat and it gives:
# grep SFC tmp.dat
SFC_ID,
# perl -pe 's/(^SFC_ID,$)/\1""/' tmp.dat | grep SFC
SFC_ID,""
Removing the anchors also works, but migh latch on to replacements you did not intent:
# perl -pe 's/(SFC_ID,)/\1""/' tmp.dat | grep SFC
SFC_ID,""
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2004 05:38 PM
12-01-2004 05:38 PM