- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed question
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
тАО08-09-2001 07:54 AM
тАО08-09-2001 07:54 AM
user1 user2 user3 user4
to this:
user1
user2
user3
user4
When we use the following sed command:
sed 's/ /\\n/g' file
we get this
user1\nuser2\nuser\nuser4
Any ideas on how to do this, or how to make sed not look print the \n litteraly?
Thanks in advance.
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-09-2001 08:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-09-2001 08:20 AM
тАО08-09-2001 08:20 AM
Re: sed question
Here's one way to do it in awk.
cat myfile | awk '{ n = split($0,arry); i = 1; while (i <= n) { printf("%s\n",arry[i]); ++i; } }' > newfile
All on one line.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-09-2001 08:56 AM
тАО08-09-2001 08:56 AM
Re: sed question
While I like 'tr' for this, here's another, short 'awk', given your input in a file called /tmp/myfile":
# awk '{for (i=1;i
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2001 06:49 AM
тАО08-10-2001 06:49 AM
Re: sed question
cat file | paste - - - -
would give you four entries per line.
-dlt-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2001 09:05 AM
тАО08-12-2001 09:05 AM
Re: sed question
sed 's/ //g'
You need a literal newline - sed doesn't understand \n in the replacement part. (If your shell is csh you'll need two \s in there.)
While at it, the shortest way to do it with awk is probably this:
awk 1 RS=' '
I wouldn't recommend that in production code though... (and it does result in an extra newline at the end of the file).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2001 11:53 PM
тАО08-12-2001 11:53 PM