![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Join Every 5 Lines With $ Symbol | ntgobinath | Shell Programming and Scripting | 3 | 05-08-2008 10:01 AM |
| to join the corresponding lines using shell commands or awk | cdfd123 | Shell Programming and Scripting | 7 | 12-10-2007 04:45 PM |
| Awk Join multiple lines | hitmansilentass | Shell Programming and Scripting | 5 | 10-27-2006 11:04 AM |
| join two lines when the second line contains "US DOLLAR" | powah | Shell Programming and Scripting | 2 | 10-21-2005 06:30 PM |
| join two lines together | tine | Shell Programming and Scripting | 4 | 12-12-2003 12:34 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
how to join lines
can anyone tell me as "how to join all lines in a file " using a shell script
Actually i have many files in a directory and for each file i want to join all the lines using a shell scrip . Thanks in advance!!! |
|
||||
|
echo " Enter the dir name: [Give full path] "
read dir cd $dir for file in `ls` do if [ -f $file ]; then # Plz try to check & avoid *.gz , *.out & *.4ge # and other binary files echo `cat $file`> $file fi done Last edited by Niroj; 09-11-2008 at 08:09 AM.. |
|
||||
|
That's a Useless Use of ls in Backticks there. You mean
Code:
for file in * Code:
tr -d '\n' <"$file" >tmp; mv tmp "$file" If you want to replace each newline with a space, that's also easy to do with tr. |
|
||||
|
ok...Herder of Useless Cats..
cool... I knew the result thats why I suggested this... Ex. cat > File ============= hi era bye ========= tr -d '\n' <"File" >tmp; mv tmp "File" ===== cat file ---------------- hi erabye # Any one need this type of joining.. ??! ================================================ And 2nd one ... If you think "translating each '\n' char to NULL value; then creating a temp file and then renaming the temp file to acutual file name to make it permanent .. " is faster and better idea.. Then I don't need to say anything...!! Last edited by Niroj; 09-11-2008 at 09:12 AM.. |
|
||||
|
Depends on the requirements, obviously. If you want spaces then (as hinted) try
Code:
tr '\n' ' ' <File >tmp Code:
perl -i~ -pe 'y/\n//d' file # or 'y/\n/ /' if you want to join with spaces |
|
||||
|
Quote:
What a greate idea..as if anyone know these...?!!Plese don't make thse silly comments.. Then tell me why using cat is useless... echo `cat $file`> $file ? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|