- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: using "for' in script
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
тАО11-28-2004 05:10 AM
тАО11-28-2004 05:10 AM
I have a file which contains a list of backup names, some names have spaces some don't, when using the following it appears that the names with space are treated as two.
for i in `cat $file1 | awk -F"\t" '{print $1}'`;do
echo $i
done
file1 contains things like:
backup1 offline
backup2_online
etc...
I am sure there is a way around this but cannot find it.
Please help
Sebastien
Solved! Go to Solution.
- Tags:
- evil spaces
- for loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2004 05:34 AM
тАО11-28-2004 05:34 AM
Re: using "for' in script
try with qoutes
echo "$i"
regards,
John K.
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2004 06:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2004 06:20 AM
тАО11-28-2004 06:20 AM
Re: using "for' in script
That was pretty fast, Slawomir's suggestion worked just fine using this:
cat $file1|awk -F"\t" '{print $1}'|while read
do
echo ${REPLY}
done
thanks again
sebastien
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2004 06:27 AM
тАО11-28-2004 06:27 AM
Re: using "for' in script
The problem is you are in effect writing
for i in backup1 offline backup2_online
do
...
done
So the for loop cannot differentiate (even with quotes). You need to join them together. Perl would probably be the tool of choice, but as you've chosed awk I'll do it like so...Try
for i in $(cat file | awk -F"\t" '{print $1}' | sed -e "s/\ /:/g")
do
j=$(echo $i | sed "s/:/\ /g")
etc...
done
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2005 11:26 AM
тАО10-06-2005 11:26 AM
Re: using "for' in script
For example, if I get the file name into variable j, the stmt #cp /here/$j /there/$j will parse out the filename up to the first space.
any suggestions ?
Lisa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2005 04:03 PM
тАО10-06-2005 04:03 PM
Re: using "for' in script
cp "/here/${j}" "/there/${j}"
Disciplined shell programmers get into the habit of encloses all variables with {}'s and quoting as well because whitespace has always been legal (if dumb) in UNIX pathnames.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2005 05:28 PM
тАО10-06-2005 05:28 PM
Re: using "for' in script
while read line;
do
echo $line
done <
It is more efficient than cat file | while.
===
lisa,
You can use methods as,
touch "hi bye"
here hi bye is a single file name.
var="hi bye"
You can move as,
# mv "$var" hi
or
# mv ${var} hi
hth.