The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-21-2006
ugh ugh is offline
Registered User
 

Join Date: Mar 2006
Posts: 7
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
Reply With Quote
Forum Sponsor
  #2  
Old 03-22-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,016
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}"
Reply With Quote
  #3  
Old 03-27-2006
ugh ugh is offline
Registered User
 

Join Date: Mar 2006
Posts: 7
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0