![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MX redirecting | nbredthauer | UNIX for Advanced & Expert Users | 11 | 10-02-2007 08:57 AM |
| redirecting a file | wip_vasikaran | Shell Programming and Scripting | 3 | 07-12-2007 01:14 AM |
| problems in redirecting TOP | rana_d | SUN Solaris | 7 | 07-26-2006 08:14 AM |
| redirecting gcc messages | rakkota | High Level Programming | 3 | 04-06-2006 12:48 PM |
| Redirecting | svh | High Level Programming | 5 | 08-21-2005 09:08 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
using redirecting from awk
Well this is what im doing, im writing a script that you pass 3 variables into. Filename, delimiter or "FS in AWK", and a string of columbs you want to keep 1,2,4,5... Just modifing a data file and rewriting with a different extension.
My problem atm is using awk to seperate the "columb String" **Input runme.sh filename.txt "|" 1,2,4,5** echo $3 | awk -F"," ' {for (i=1;i <=NF;i++) print $i }' |**well i want this redirected into an array.. **Output from this command gives me 1 2 4 5 I need to rebuild this into another awk command."like this" to get my needed data needs to be awk -F"$dell" -v dell=$dell 'BEGIN{OFS= dell }{print $2,$4,""} <--dynamic END{Print"for Kicks"}' $filename > newoutputfile.txt ********************************************** OK found a solution myself this is in KSH echo $time | awk -F"," '{ORS=" " }{OFS=""}{for(i=1;i <=NF;i++) print "$",$i }' | read ouput set -A array $output echo ${array[0]} echo ${array[1]} echo ${array[3]} Last edited by ugh; 03-22-2006 at 08:18 AM. Reason: Found the solution to the problem |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
something to start with - not tested:
Code:
#!/bin/ksh
filename='myFile'
newEXT='.new'
columns2keep='1 2 4 5'
del=','
nawk -F"${del}" -v cols="${columns2keep}" '
BEGIN {
OFS=FS
n=split(cols, colsA, " ")
}
{
for(i=1; i <= n; i++)
printf("%s%s", $colsA[i], (i<n) ? OFS : "\n")
}
' "${filename}" > "${filename}${newEXT}"
|
|
#3
|
|||
|
|||
|
Thanks
Thanks Vgersh99 that looks close to what i need, though i cant use nawk and i dont think i can manipulate the output string the same way in awk. I ended up using a different method, crude but it worked.
filename=$1 dell=$2 keep=$3 echo $keep | awk -F"," '{ORS=" " }{OFS=""}{gtw=","} {for(i=1;i <=NF;i++){ print "$",$i,gtw; if((i+1) == NF) gtw="" } }' | read output i="awk -F\"$dell\" 'BEGIN{OFS=FS}{print $output}' $filename" echo $i > temp.sh chmod 700 temp.sh temp.sh |
|||
| Google The UNIX and Linux Forums |