- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Replace a Blank Char to ~ (tilde) Using 'sed' Comm...
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
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
тАО09-17-2009 03:09 AM
тАО09-17-2009 03:09 AM
I have an output below:
bdhp4126.na.pg.com ~17 Sep 2009~06:45:01~W~FILE
I want to add tilde (~) between date and month (char 29), and between month and year (char 33). So the output will be like below:
bdhp4126.na.pg.com ~17~Sep~2009~06:45:01~W~FILE
How can we do that using sed command? Please help. Thanks in advance.
Regards,
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 03:19 AM
тАО09-17-2009 03:19 AM
SolutionUsing perl:
$ cat x
bdhp4126.na.pg.com ~17 Sep 2009~06:45:01~W~FILE
$
$ perl -pe "s/(\d+) (\w+) (\d+)/\1~\2~\3/" x
bdhp4126.na.pg.com ~17~Sep~2009~06:45:01~W~FILE
So that looks for some numbers followed by a space stored in $1 (day)
followed by a word stored in $2 (month)
followed by a space and more numbers in $3 for the year.
Re-assemble with the tildes.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 03:37 AM
тАО09-17-2009 03:37 AM
Re: Replace a Blank Char to ~ (tilde) Using 'sed' Command
awk '{ print $1" "$2"~"$3"~"$4 }
OR
awk '{
a=substr($0,1,22)
b=substr($0,24,3)
c=substr($0,28,20)
print a~b~c
}'
or
awk '{
print substr($0,1,22)"~"substr($0,24,3)"~"substr($0,28,20)
}'
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 03:44 AM
тАО09-17-2009 03:44 AM
Re: Replace a Blank Char to ~ (tilde) Using 'sed' Command
awk '{ print $1" "$2"~"$3"~"$4 }'
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 04:19 AM
тАО09-17-2009 04:19 AM
Re: Replace a Blank Char to ~ (tilde) Using 'sed' Command
Your requirement, based on the data presented, seems as simple as replacing blank characters with tildes. If that's truly the case, using 'sed' (as requested) this becomes:
# X="bdhp4126.na.pg.com ~17 Sep 2009~06:45:01~W~FILE"
# echo ${X}|sed -e 's/[ ]/~/g'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 05:46 AM
тАО09-17-2009 05:46 AM
Re: Replace a Blank Char to ~ (tilde) Using 'sed' Command
Got it. Resolved the issue using perl command as advised above. Thanks alot to you all for the great help.
Best Regards,