Help with column specification


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with column specification
# 1  
Old 06-26-2012
Help with column specification

Hi I am working on a program that reads a file with multiple columns and was curious how to specify the columns to be manipulated in the command line.
For example the file may look something like:

Code:
 
Column1   Column2   Column3   Column4   Column5  Column6
AC           82542      3525       GG           154124   541556

I would like to be able to type either "column1" or "column4" in the command line and have they print out the contents of the column put in as input as well as the contents of the two columns that follow.

Given the file above and typing "column4" on the command line, I would like the output to be:
Code:
GG 154124 541556

I would greatly appreciate all help.
Thanks a lot.
Drossy
# 2  
Old 06-26-2012
Hi,
Guessing you'd need something like this...

Code:
  COLUMN_NO=$1
  
  case  $COLUMN_NO in
  column_1 )
      awk -F [ ' '] ' { print $1, $2, $3, $4, $5, $6' } < yourfilename
       ;;
  column_2 )
      awk -F [ ' '] ' { print $2, $3, $4, $5, $6' } < yourfilename
       ;;
  column_3 )
      awk -F [ ' '] ' { print $3, $4, $5, $6' } < yourfilename
       ;;
   column_4 )
      awk -F [ ' '] ' { print $4, $5, $6' } < yourfilename
       ;;
  column_5 )
      awk -F [ ' '] ' { print $5, $6' } < yourfilename
       ;;
  column_6 )
      awk -F [ ' '] ' { print $6' } < yourfilename
             ;;      
    esac
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Help with touch: bad time specification

Here is the part of the script: I have modified the file name.:) SSFILE=${My_HOME_DIR}/log/my_file_ss.log export MM=`date '+%m'` export DD=`date '+%d'` export HH=`date '+%H'` export MIN=`date '+%M'` export HOURAGO=`echo ${HH} -1 |bc ` echo $HOURAGO export TTIME=${MM}${DD}${HOURAGO}00... (5 Replies)
Discussion started by: N1a_Raider
5 Replies

2. AIX

sudo - User privilege specification

I am planning to implement sudo for users. Under , it looks I have to put the users who need to have sudo access: What are the recommended for users? I don't think I need to give the ALL privilege (i.e ) to AIX users. I'd like to know the commonly used privilege specification for sudo... (9 Replies)
Discussion started by: Daniel Gate
9 Replies

3. Solaris

Getting server specification

Hi all, Can anyone help me to get the server specifications like the following? eg. SUN Fire XXX X UltraSPARC X MHZ X MB Memory X GB od hard disk X On board PCI IO card X PCI HNI card Thanks. (4 Replies)
Discussion started by: beginningDBA
4 Replies

4. UNIX for Dummies Questions & Answers

RSC card specification

Hi I have a SUN box that i am supporting Model 480r . The RS card that is attached to it is giving some problems . It is pinging but i am unable to telnet into it therefore having no remote TC console access ( the system is currently up ) Is there a way by which i can remotely check the... (1 Reply)
Discussion started by: Sam4u
1 Replies

5. Shell Programming and Scripting

Range specification in for loop

Hello Friends, I want to use range in for loop. For that i used (..) operator but it is not working. Ex: for i in 1..24 do echo $i done Instead of printing 1 to 24 nos, it gives o/p as: 1..24 Please help me Thanks in advance. (2 Replies)
Discussion started by: Niyati
2 Replies

6. Solaris

System specification checking

Hi, anybody know how to check the system specification for the unix by using the command like the memory size, cpu's speed and etc. Thanks. (3 Replies)
Discussion started by: efang
3 Replies

7. Solaris

hardware specification ( very Urgent please )

I wana know my box hardware specification ( Like RAM , processor speed .... Etc ) and used version of Solaris i mean (SPARC, 32-bit) or (x86, 32-bit) or(SPARC, 64-bit) or what ?? very Urgent please (5 Replies)
Discussion started by: KSA
5 Replies

8. UNIX for Dummies Questions & Answers

Sed character number specification

I have the following sed command: sed '/7361105/s/^\(..............................................................................................................................................................................\)....\(.*\)/\16776\2/' arch.txt > arch.tmp && mv arch.tmp arch.txt ... (4 Replies)
Discussion started by: mvalonso
4 Replies

9. What is on Your Mind?

Internation Standards Networking Specification

I seem to get lost when it comes in terms of Networking types and its specifications by different International bodies. I am not able to understand things like - "synchronous operation on public data networks networking protocol" "packet mode connected to public data networks by dedicated... (1 Reply)
Discussion started by: S.P.Prasad
1 Replies

10. UNIX for Dummies Questions & Answers

HD specification

What command do I use to determine how many/what kind/how big the hard drives on a box are? (2 Replies)
Discussion started by: abolshoun
2 Replies
Login or Register to Ask a Question