LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-30-2010, 09:18 AM   #1
NothingToLose
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Rep: Reputation: 0
Append numbers to a word list? cat...


If I do:
for i in $(cat names); do seq -f "$i%03.0f" 0 999; done > output5.txt
I got ( tail snipped):
997munt
998munt
999munt
If I do:
for i in $(cat names); do seq -f "%03.0f$i" 0 999; done > output4.txt
I got:
997Zygmunt
998Zygmunt
999Zygmunt
How I can get numbers from 000 to 999 appended like:
Zygmunt997
Zygmunt998
Zygmunt999
 
Old 12-30-2010, 09:27 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Where did the "Zyg"s come from in the second example?
 
Old 12-30-2010, 10:28 AM   #3
NothingToLose
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Correct word on the list is with "Zyg" Zygmunt etc... I wonder more where the Zyg disapperead & why the number did not come behind?
 
Old 12-30-2010, 10:41 AM   #4
NothingToLose
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Or is it the list which makes problems?

A'Leshia
Aarika
Aaron
Abas
Adrian Belew
Adriana
Adrianna
Zvi
Zvonko
Zygmunt
 
Old 12-30-2010, 10:46 AM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,467

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
Works for me:

Code:
$ cat names
A'Leshia
Aarika
Aaron
Abas
Adrian Belew
Adriana
Adrianna
Zvi
Zvonko
Zygmunt
$ for i in $(cat names); do seq -f "%03.0f$i" 0 999; done | tail -3
997Zygmunt
998Zygmunt
999Zygmunt
$ for i in $(cat names); do seq -f "$i%03.0f" 0 999; done | tail -3
Zygmunt997
Zygmunt998
Zygmunt999
 
Old 12-30-2010, 11:14 AM   #6
NothingToLose
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Original Poster
Rep: Reputation: 0
There has to be something strange on my Shell? Ubuntu Lucid...
 
Old 12-30-2010, 11:25 AM   #7
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 329

Rep: Reputation: 140Reputation: 140
The names file could contain carriage return characters if it was made in Windows.
\n is the end of line code for Linux
\r\n is the end of line code for Windows
\n represents a newline character
\r represents a carriage return character
Code:
# $'\r' gives a carriage return character in bash
i=Zygmunt$'\r'   # append a carriage return character

echo "${i}999"
999munt

# Using bash parameter expansion to remove the carriage return
echo "${i%$'\r'}999"
Zygmunt999
 
Old 12-30-2010, 01:06 PM   #8
NothingToLose
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks! It was the carriage return. I did: tr -d '\r' < names.txt > newNames.txt
 
Old 12-30-2010, 08:36 PM   #9
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,541

Rep: Reputation: 1919Reputation: 1919Reputation: 1919Reputation: 1919Reputation: 1919Reputation: 1919Reputation: 1919Reputation: 1919Reputation: 1919Reputation: 1919Reputation: 1919
Please mark as SOLVED once you have a solution
 
  


Reply

Tags
cat


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sed append word at end of line if word is missing franjo124 Linux - Newbie 3 03-08-2012 08:41 PM
Need advice on a script to search many files for list of terms, append hits to list jimmy the saint Programming 1 07-11-2010 03:59 AM
Kate: Append files to existing list and enable the Recent List AGazzaz Linux - Software 2 10-13-2009 08:27 PM
[SOLVED] Using an expect Script to send the output of cat and append it to a file spoofedexistence Programming 1 09-29-2009 03:50 PM
The HorizSync key word must followed by a list of numbers or ranges comox *BSD 2 03-14-2005 03:57 AM


All times are GMT -5. The time now is 02:10 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration