LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Help with bash commands (http://www.linuxquestions.org/questions/linux-general-1/help-with-bash-commands-463665/)

cmfarley19 07-13-2006 09:50 AM

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

homey 07-13-2006 10:31 AM

Were you thinking of something like this?
Code:

sed -e 's/^.*$/"&",/' file.txt

druuna 07-13-2006 10:36 AM

Hi,

This should do thye trick:

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

Hope this helps.

cmfarley19 07-13-2006 10:41 AM

Bingo!

Nicley done.

Thank you.

cmfarley19 07-14-2006 07:38 AM

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

homey 07-14-2006 07:56 AM

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

cmfarley19 07-14-2006 08:04 AM

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.


All times are GMT -5. The time now is 10:19 AM.