- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- While Loop 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
тАО10-13-2009 02:59 PM
тАО10-13-2009 02:59 PM
emailid1 word1 word2 word3
emailid2 word1 word3
The spaces between the words are tab separated spaces.
I want to echo each word on the line separately and at the same time consider the next line as a new line.
Please help!
Solved! Go to Solution.
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2009 03:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2009 03:06 PM
тАО10-13-2009 03:06 PM
Re: While Loop Question?
There is one more piece to it, the words can be more than 3 and the count cannot be predicted. I need a more dynamic way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2009 03:19 PM
тАО10-13-2009 03:19 PM
Re: While Loop Question?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2009 03:22 PM
тАО10-13-2009 03:22 PM
Re: While Loop Question?
while read LINE
do
echo ${LINE}|tr -cs "[:alpha:]" "[\012*]"
done < file
Spaces and/or tabs can separate the words in the file.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2009 03:27 PM
тАО10-13-2009 03:27 PM
Re: While Loop Question?
> And dont want to print blank lines.
OK, so use:
# cat ./lister
#!/usr/bin/sh
while read LINE
do
[ -z "${LINE}" ] && continue
echo "${LINE}"|tr -cs "[:alpha:]" "[\012*]"
done < $1
...run as:
# ./lister file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2009 03:36 PM
тАО10-13-2009 03:36 PM
Re: While Loop Question?
In keeping with TIMTOWDI here's another way:
# perl -nle 'next if m/^\s*$/;print join "\n",split' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2009 03:46 PM
тАО10-13-2009 03:46 PM
Re: While Loop Question?
But this doesn't do what I want to achieve -
Email-ids are of the pattern foo_bar@foobar.com and it is the first entry on each line.I want to print that as is and add a certain html tags around it -
and for the words like words1... I need
...
The final document should look like the following -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2009 04:00 PM
тАО10-13-2009 04:00 PM
Re: While Loop Question?
for word in $(< file); do
echo $word
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2009 05:42 PM
тАО10-13-2009 05:42 PM
Re: While Loop Question?
Seems like your original problem statement can be satisfied with a simple:
$ tr "\t" "\n" < tmp.txt
look:
$ cat tmp.txt
asergfewgfwegfew aap noot mies
blah more data
$ od -c tmp.txt
0000000 a s e r g f e w g f w e g f e w
0000020 \t a a p \t n o o t \t m i e s \n b
0000040 l a h \t m o r e \t d a t a \n
$ tr "\t" "\n" < tmp.txt
asergfewgfwegfew
aap
noot
mies
blah
more
data
But that's not really what you want apparently, and it looses the 'specialness' of the first word. Why not do it all in one perl one-line or program?
$ perl -ne 'chomp; @words=split; $u=shift @words; print "
/word>\n"}; print "
Enjoy!
Hein