![]() |
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 |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to check Null values in a file column by column if columns are Not NULLs | Mandab | Shell Programming and Scripting | 7 | 03-15-2008 09:57 AM |
| Pulling a file off a backup tape | rocker40 | UNIX for Dummies Questions & Answers | 14 | 10-12-2007 12:37 PM |
| Pulling data and following lines from file | MizzGail | Shell Programming and Scripting | 2 | 01-31-2006 03:13 PM |
| pulling the following line from a file | peter.herlihy | UNIX for Dummies Questions & Answers | 4 | 08-29-2002 10:09 PM |
| Pulling out fields from a file | Saz | UNIX for Advanced & Expert Users | 2 | 09-30-2001 04:31 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
pulling a column from a file in ksh
I would like to pull a column from a file and place it in a variable:
The file would look like this: N.Korea gibberish garbage S.Korea gibberish garbage USA gibberish garbage Iraq gibberish garbage Canada gibberish garbage and items in the first column would be one word only. I would like to place the whole column in a variable. I think sed would be good for this, but I'm not sure of the syntax. Thanks |
|
|||||
|
This is not csh syntax, it is ksh syntax. Note that the title of this thread explicitly mentions ksh. In ksh, the $(command) is preferred, while the `command` syntax is currently supported for backward compatibility.
The advantage is nesting: gcos=$(grep $(whoami) /etc/passwd | cut -d: -f5) is easy to code and easy to read. Depending on the contents of the gcos field: eval gcos=\`grep `whoami` /etc/passwd \| cut -d: -f5 \' may or may not work. |
|
||||
|
Well, here's where it gets tricky:
It turns out that I do need to use the second column. The file would now look like this: N.Korea NUCLEAR garbage S.Korea NON-NUCLEAR garbage USA NUCLEAR garbage Iraq UNKNOWN garbage Canada HORSEBACK garbage (By the way, the second column is a joke, for those who don't get my sense of humor) But what I need to do is pull out the second column and place it in a separate variable, but in a way that I can still associate it with the first column. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|