LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 07-13-2006, 10:50 AM   #1
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Rep: Reputation: 32
Help with bash commands


Greetings all...
I think this should be relatively easy for the sed/awk experts here.
I have a text file that contains the names of several hundred classes that a project I am working contains. The contents look like so:
Code:
AAxis
AAxisConfigDialog
AboutMenu
AMotor
AnimatedDiagnosticsWindow
AutoConfigMenu
AutomationConfig
AxisConfig
AxisConfigDialog
BaseThread
BAxis
BitPacker
BlkSelectDialog
Block
...
I am looking for a simple commande to pipe to from cat to make the contents look like so:
Code:
"AAxis",
"AAxisConfigDialog",
"AboutMenu",
"AMotor",
"AnimatedDiagnosticsWindow",
"AutoConfigMenu",
"AutomationConfig",
"AxisConfig",
"AxisConfigDialog",
"BaseThread",
"BAxis",
"BitPacker",
"BlkSelectDialog",
"Block",
...
I have taxed my limited sed skills and am coming up snake eyes.

Any thoughts?

Chris
 
Old 07-13-2006, 11:31 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Were you thinking of something like this?
Code:
sed -e 's/^.*$/"&",/' file.txt
 
Old 07-13-2006, 11:36 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

This should do thye trick:

sed 's/\(.*\)/"\1",/' infile

Hope this helps.
 
Old 07-13-2006, 11:41 AM   #4
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Original Poster
Rep: Reputation: 32
Bingo!

Nicley done.

Thank you.
 
Old 07-14-2006, 08:38 AM   #5
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Original Poster
Rep: Reputation: 32
Thanks again for the help.

After a closer look, here is what I am seeing...
I issue the command:
Code:
cat classes3.txt
and I see:
Code:
...
ScreenCalib
SensorConfigDialog
SerialPort
SetupMachineWindow
SetupMenu
SmartIO
Speed
Strings
SurfaceCntMenu
SystemConfig
SystemStatus
TextBox
Thread
ThreadWindow
TouchTestDialog
TuneMotorWindow
...
I issue the command:
Code:
 cat classes3.txt |sed 's/\(.*\)/"\1",/'
and I see:
Code:
...
",creenCalib
"SensorConfigDialog",
",erialPort
"SetupMachineWindow",
"SetupMenu",
",martIO
"Speed",
",trings
"SurfaceCntMenu",
",ystemConfig
",ystemStatus
"TextBox",
",hread
"ThreadWindow",
"TouchTestDialog",
"TuneMotorWindow",
...
Note that some of the lines begin by replacing the first letter
with the terminating ", and end with nothing.

I don't see anything unique about those lines or the previous one that might cause that behaviour.

Any thoughts?

Chris
 
Old 07-14-2006, 08:56 AM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
If the file was created/modified on Windows, you may want to convert it to Linux format with a command like this...
Code:
cat file.txt | tr -d '\015' >file1.txt
 
Old 07-14-2006, 09:04 AM   #7
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Original Poster
Rep: Reputation: 32
The original source fileswere created in windows, but have been processed by many perl/bash script to yield the finaltext file above. Perhaps some of the crazy windows got carried throught the text processing.

Anyway...
I ran the conversion you suggested and now the original sed command appears to give me the desired result.

Thanks Guys.
 
  


Reply

Tags
bash, commandline, shell script


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash commands davatar Slackware 2 04-06-2005 04:05 AM
bash commands Obie Linux - Security 4 08-15-2004 03:42 PM
Help with BASH Commands rridler Linux - Newbie 3 04-16-2004 05:43 PM
Bash commands PhuckFonix Linux - Newbie 2 03-30-2004 08:13 PM
Bash commands wprescott Linux - Distributions 6 04-27-2002 03:56 PM


All times are GMT -5. The time now is 10:50 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