Printing line in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing line in shell script
# 1  
Old 05-04-2015
Code Printing line in shell script

Need assistance in getting a shell program .
I have csv file and each line has comma separated number. I wanted to take of the comas and print each number in each line . below example. Appreicate your help

Row with number
Code:
KCAR,31,62,36,69,41,75,46,78,55,70,44,69,41,65,40,63,41,61,42,64,43,66,41,65,44,66,44,68,46,69

Need to be printed as
Code:
KCAR
max 31
min 62
avg 63
max 69
min 41
avg 75

and soo on
# 2  
Old 05-04-2015
Please show us your attempts at solving this.
# 3  
Old 05-04-2015
balajesuri

Below is the command I used and finding another way to shorten the command or script

Code:
awk 'BEGIN { FS = "," } ; { print $1"""\nmax "$2"\nmin "$3  }'

# 4  
Old 05-04-2015
Code:
$ awk -F, '{print $1; for (i=2;i+2<=NF;i+=3) printf("max %d\nmin %d\navg %d\n", $i, $(i+1), $(i+2))}' input
KCAR
max 31
min 62
avg 36
max 69
min 41
avg 75
max 46
min 78
avg 55
max 70
min 44
avg 69
max 41
min 65
avg 40
max 63
min 41
avg 61
max 42
min 64
avg 43
max 66
min 41
avg 65
max 44
min 66
avg 44
max 68
min 46
avg 69


Last edited by neutronscott; 05-04-2015 at 01:05 PM..
This User Gave Thanks to neutronscott For This Post:
# 5  
Old 05-04-2015
Thank you neutronscott. Appreciate your help
# 6  
Old 05-04-2015
Try
Code:
 awk -F, 'BEGIN {n=split ("max,min,avg", TMP)} {print $1; for (i=2; i<=NF; i++) print TMP[(i-2)%3+1], $i}' file

# 7  
Old 05-04-2015
Quote:
Originally Posted by RudiC
Try
Code:
 awk -F, 'BEGIN {n=split ("max,min,avg", TMP)} {print $1; for (i=2; i<=NF; i++) print TMP[(i-2)%n+1], $i}' file

nice. Smilie i fixed that for ya. Smilie
This User Gave Thanks to neutronscott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed , awk script for printing matched line before regular expression

hi All , I am having a large file with lots of modules as shown below ############################################### module KKK kksd kskks jsn;lsm jsnlsn; Ring jjsjsj kskmsm jjs endmodule module llll 1kksd11 k232skks j33sn;l55sm (6 Replies)
Discussion started by: kshitij
6 Replies

2. Shell Programming and Scripting

Help with printing new line in shell script

I'm having a script which outputs four different attributes A, B, C, D for a list of users. I want to insert expression such that once the output is generated for first user, output for next user should be printed in new line. Please help. (4 Replies)
Discussion started by: surdileep
4 Replies

3. Shell Programming and Scripting

Need help in Perl Script for printing next line

I got multiple of documents in which i have to extract a line coming after a ID..The scenario is Customer ID: none VT : 002/89 Customer ID: Yes VT: 001/89 Customer ID: none VT: 006/85 Customer ID: Yes VT: 003/56 I have to extract the id which is coming after YES..The output... (7 Replies)
Discussion started by: rajkrishna89
7 Replies

4. Shell Programming and Scripting

Need help with Korn Shell script for substring printing

Hi all, I am new to scripting. I have a file with colon separated values called mylist.txt cat mylist.txt 192.123.76.89:lmprod89 162.122.20.28:lmtstserver28 10.80.32.139:hewprod139 . . using our internal os utility (called mvsping) we need to check all these servers if they are... (6 Replies)
Discussion started by: kraljic
6 Replies

5. Shell Programming and Scripting

Printing from Shell Script

My print alias that works fine from the command line does not function from withn a shell script. Instead of actually performing the printing, it instead writes out the name of the file I'm trying to print. Does anyone know why? Much Thanks. (3 Replies)
Discussion started by: ttilsch
3 Replies

6. Shell Programming and Scripting

Printing the line number in bash script

Hi, I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened. Thanks, (6 Replies)
Discussion started by: suryaemlinux
6 Replies

7. Shell Programming and Scripting

shell script, why isn't if printing message?

Why isn't printing message? 1 #!/bin/sh 2 3 something(){ 4 echo "Inside something" 5 echo $1 $2 6 } 7 val=$(something "Hello " "world") But it prints. 1 #!/bin/sh 2 3 something(){ 4 echo "Inside something" 5 echo $1 $2 6 } 7... (4 Replies)
Discussion started by: cola
4 Replies

8. Shell Programming and Scripting

help needed in a shell script for printing files

Hi All, I am writing a shell script to print all the files in a particular folder. This script is on solaris server . I am using the lp command to send the requests . lp -d printername filename . The output I get is the request id. Is there any way I can use the request Id to determine if... (1 Reply)
Discussion started by: shahshilpa
1 Replies

9. Shell Programming and Scripting

Problem printing the property of xml file via shell script

Hi, I have a config.xml which cointains the tags like <CONFIG> <PROPERTY name="port" value="1111"/> <PROPERTY name="dbname" value="ABCDE"/> <PROPERTY name="connectstring" value="xyz/pwd"/> </CONFIG> This file is in some directory at UNix box. I need to write a... (4 Replies)
Discussion started by: neeto
4 Replies

10. Shell Programming and Scripting

printing last argument in shell script

All, I am having a shell script and i will pass different argument diferent time . Please tell me how can i find the last argument that i passsed each time when i exec the script. Thanks, Arun. (5 Replies)
Discussion started by: arunkumar_mca
5 Replies
Login or Register to Ask a Question