Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
sx9Offline
Post subject: Formatting text files via commandline  PostPosted: 22.10.2010, 11:34



Joined: 2010-09-12
Posts: 219
Location: Wiesbaden,Germany
Status: Offline
How can I format such a text-file format:

      Code:

command
arg1
arg2
arg3
...


in this format:

      Code:

command arg1 arg2 arg3 ...


The text file is auto-generated by one of my scripts so I need a commandline to fix this in my script.
The number of arg entries is also not predefined, so the command should detect the entry and execute the action for each entry (something like
for entry in ...
do
...
done )

Here is the script, if you are inerested in: http://pastebin.ca/1969851

_________________
My new self-made computer:
Intel Core i7-2600k
ASUS Maximus IV Gene-Z (Mainboard)
2x4GB DDR3 RAM
ATI Radeon HD 6770
OCZ Vertex 3 60GB (SSD)
Western Digital Caviar Green WD20EARX 2TB (HDD)
...
aptosid x86_64
 
 View user's profile Send private message Send e-mail Yahoo Messenger  
Reply with quote Back to top
DonKultOffline
Post subject: RE: Formatting text files via commandline  PostPosted: 22.10.2010, 12:34
Team Member


Joined: 2010-09-02
Posts: 482

Status: Offline
beside that your script includes a lot of false-friend-finds* have you tried in line 36
      Code:
exlist="$( cat /tmp/exlist | tr '\n' ' ')"
?

* What i mean with false-friends?
The * in your find statements is evaluated by your shell - find doesn't do anything in these examples.

Line 12 could look like this instead
      Code:
find /etc/console-setup/ -name '*.gz' -type f

to begin with.

See the manpages of cat (don't use grep if you mean cat!), tr and find for details and better usages.

_________________
MfG. DonKult
"I never make stupid mistakes. Only very, very clever ones." ~ The Doctor
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
sx9Offline
Post subject: RE: Formatting text files via commandline  PostPosted: 22.10.2010, 12:47



Joined: 2010-09-12
Posts: 219
Location: Wiesbaden,Germany
Status: Offline
Ah! Thank you!

Does cat also print it correctly?

_________________
My new self-made computer:
Intel Core i7-2600k
ASUS Maximus IV Gene-Z (Mainboard)
2x4GB DDR3 RAM
ATI Radeon HD 6770
OCZ Vertex 3 60GB (SSD)
Western Digital Caviar Green WD20EARX 2TB (HDD)
...
aptosid x86_64
 
 View user's profile Send private message Send e-mail Yahoo Messenger  
Reply with quote Back to top
sx9Offline
Post subject: RE: Formatting text files via commandline  PostPosted: 22.10.2010, 12:54



Joined: 2010-09-12
Posts: 219
Location: Wiesbaden,Germany
Status: Offline
Cool! It works perfectly!

_________________
My new self-made computer:
Intel Core i7-2600k
ASUS Maximus IV Gene-Z (Mainboard)
2x4GB DDR3 RAM
ATI Radeon HD 6770
OCZ Vertex 3 60GB (SSD)
Western Digital Caviar Green WD20EARX 2TB (HDD)
...
aptosid x86_64
 
 View user's profile Send private message Send e-mail Yahoo Messenger  
Reply with quote Back to top
broweOffline
Post subject: RE: Formatting text files via commandline  PostPosted: 22.10.2010, 13:22



Joined: 2010-09-12
Posts: 152
Location: Canada
Status: Offline
In this case cat looks like the right command to use, you're just looking for a dump of the exlist file into the exlist variable. Have you considered using one find command (all the searches on the same line) instead of 20+... just a thought. Or you could use a python script, it could give you more flexibility. Other commands you might consider in the script are "ls" and "locate". In any case, I'd run it a few times with different options and check it with the time command, as well as watching cpu usage. A little tweaking could speed up this script a bit although most of the time will be just spinning the disk.
 
 View user's profile Send private message  
Reply with quote Back to top
sx9Offline
Post subject: RE: Formatting text files via commandline  PostPosted: 22.10.2010, 16:49



Joined: 2010-09-12
Posts: 219
Location: Wiesbaden,Germany
Status: Offline
I've already used ls and I find it is more secure to make seperate commands and let them run. Of course this takes a "bit" more cpu-power, but I think it's worth (And my Laptop got the needed power).
One more plus is that I can easily comment lines I don't actually need.
But with all the rest you are right.
I'll think about optizing it Smile .

_________________
My new self-made computer:
Intel Core i7-2600k
ASUS Maximus IV Gene-Z (Mainboard)
2x4GB DDR3 RAM
ATI Radeon HD 6770
OCZ Vertex 3 60GB (SSD)
Western Digital Caviar Green WD20EARX 2TB (HDD)
...
aptosid x86_64
 
 View user's profile Send private message Send e-mail Yahoo Messenger  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 12 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by Zafenio