![]() |
|
|
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 |
| Scripting help | tiney83 | UNIX for Dummies Questions & Answers | 4 | 05-14-2008 09:04 PM |
| i m new to scripting | ip.bastola | Shell Programming and Scripting | 1 | 03-14-2007 01:09 AM |
| difference between AIX shell scripting and Unix shell scripting. | haroonec | Shell Programming and Scripting | 2 | 04-12-2006 09:12 AM |
| scripting guru's pls help me with scripting on AIX | thatiprashant | Shell Programming and Scripting | 1 | 01-20-2006 07:58 PM |
| Help!? with scripting... | BlueOysterCult | UNIX for Dummies Questions & Answers | 2 | 12-09-2003 06:23 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
tr, sed, awk, cat or scripting
I need to change all Newline caracters (\12) to Fieldseparator(\34).
tr -A '\12' '\34' <file1> file2 Replace all delete (\177) with Newline (\12) tr -A '\177' '\12' <file2> file3 Put the name of the file first in all rows. awk '{printf "%s\34%s\n", FILENAME,$0} file3 > file4 So far no problem. This works fine when I just need to do it with one file. Now I need to do it on 100 files. So I cant change the filename(file1>file2), and after doing all the tr commands and the awk command I need to concatenate them with: cat * > AllFilesAfterTrandAwk Here is an example: file1 contains: row1 \12 row2 \177 file2 contains: row1 \12 row2 \177 row3 data I need: file1 row1 \34 file1 row2 \12 file2 row1 \34 file2 row2 \12 file2 row3 data Does anyone have a clue? Thanks, MrKlint |
|
||||
|
Sorry, I do not follow. I havent worked with Unix before. I put my commands one by one in the prompt. If you have the time can you write the commands exactly as I'm supposed to write them?
what does $file mean? all files in the folder? like * ?? |
|
|||||
|
Scripting is merely executing commands that you could type in directly. You could have put your original example into a script "as-is". Mostly, there are exceptions, anything you type directly from Code:
ls -l to Code:
awk ..... can be put inside a script file. Note: after you save your command file, often saved with a .sh ending as in convert12.sh , you need to make the file executable with a Code:
chmod +x convert12.sh command. |
|
||||
|
This is the solution I came up with...
#!/usr/bin/sh # Create list ls F4* > tmp_file_list # Reads the list and does the restructuring while read tmp_file_list do tr -A '\12\177' '\11\12' <${tmp_file_list}> ${tmp_file_list}_1 awk '{printf "%s\11%s\n",FILENAME,$0}' ${tmp_file_list}_1 > ${tmp_file_list}_2 done < tmp_file_list # Concatenate all the files cat F4*_2 > AllFilesAfterTrAndAwk rm F4*_1 rm F4*_2 rm tmp_file_list |
![]() |
| Bookmarks |
| Tags |
| awk, cat, script, sed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|