![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | 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 !! |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Replacing a column in a text file
Say I had a text file that contained four columns, like the following:
Mack Christopher:237 Avondale Blvd:970-791-6419:S Ben Macdonor:30 Dragon Rd:647-288-6395:B I'm making a loop that will replace the fourth column a line in the file with the contents of a variable 'access', but I have no idea how to do it. I've been trying to use awk, but I don't think I am doing it correctly. Does anyone have any ideas? |
|
|||
|
Sorry for forgetting to mention that my columns were separated by a colon. So I took the code that you gave me and added an -F and this is what I have so far: Code:
awk -F ":" -v var="$access" '{$NF=var}1' file
Two things that I am still having trouble with though. 1) What does the 1 inside the single quotes do as part of awk (I'm trying to understand for future uses). 2) The output for the awk command looks like this" Mack Christopher 237 Avondale Blvd 970-791-6419 Student Access Is there a way to keep the colons? |
|
|||
|
inverser 2 colonnes dans un texte sous éditeur
On peut aussi permuter 2 colonnes sous vi, donc interactivement.
Dans ton exemple où le séparateur de colonne est ":" :%s/\(.*\):\(.*\):\(.*\):\(.*\)/\1:\3:\2:\4/ signifie : après [esc] indique une action sur le texte % l'action porte sur l'ensemble du texte s l'action est une substitution / début de description de la ligne \(.*\) un groupe contenant plusieurs caractères quelconque : sauf : qui sert de séparateur / fin de la ligne et commencement de la description de la réécriture \1 recopie le premier groupe : écrit le nouveau séparateur, ici c'est le même etc Hope, it's help you --------------------------------------------------------- (°> Dhénin Jean-Jacques / ) 48, rue de la Justice 78300 Poissy ^^ Jean-Jacques@dhenin.fr |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help parsing and replacing text with file name | mycoguy | UNIX for Dummies Questions & Answers | 2 | 08-07-2009 02:05 PM |
| replacing text in a file, but... | Angelseph | Shell Programming and Scripting | 2 | 12-06-2008 12:46 AM |
| Replacing Text in Text file | cgilchrist | Shell Programming and Scripting | 3 | 06-30-2008 11:32 PM |
| Replacing column with column of another file | manneni prakash | UNIX for Advanced & Expert Users | 1 | 06-25-2008 12:27 AM |
| Replacing column with column of another file | manneni prakash | UNIX for Dummies Questions & Answers | 1 | 06-25-2008 12:20 AM |