Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.

How to modify an output?

Thread Tools Search this Thread
# 1  
How to modify an output?

I have a list
XPAR    ,
XPAR    ,       ,
XPAR    ,1,
XPAR 196
XPAR 95,77

This has space and tabs on the second row. I would like it to look like

XPAR 1, 196, 95, 77

But I always get the below because of the spaces above.

, , ,1, 196 95 95,77

I use awk -v x="" '{ s=s sprintf(x "%s" x " ", $2) } END { sub(",$2", "", s); print(s) }' sources3 > TMPFILE

Please Help

Last edited by vbe; 02-20-2013 at 12:24 PM.. Reason: code tags for data also...
# 2  
awk -F'[, ]' ' p ~ $1 {
                        for(i=2;i<=NF;i++) {
                                if($i != "")
                                        printf ",%s",$i;
                } p !~ $1 {
                        printf "%s", $1;
                } {
                        p = $1;
                } END {
                        printf "\n";
}' file

This User Gave Thanks to Yoda For This Post:
# 3  
The script bipinajith provided puts out a <comma> before the first XPAR value, uses <comma> instead of <comma><space> to separate XPAR values, and outputs duplicated XPAR values multiple times. I think the following produces the requested output:
awk -F '[ \t,]+' '
{	for(i = 2; i <= NF; i++)
		if($i != "" && (! ($i in x))) {
			printf("%s %s", oc++ ? "," : "XPAR", $i)
END {	printf("\n")}' file

If you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk instead of awk.
This User Gave Thanks to Don Cragun For This Post:
# 5  
OR Try

$ awk '{gsub(","," ");
    X[$1]=X[$1]?X[$1]","$i:$1" "$i}}}
    END{print X[$1]}' file

XPAR 1,196,95,77

This User Gave Thanks to pamu For This Post:
# 6  
I would like to also not display the table which contains no info on the second column.
Now i have:

XPAR , ,
XPAR ,1,
XPAR 196
XPAR 95,77

I would like
XPAR 95,77
XPAR 196
Just the lines that contain a data on the second column.

Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Solaris

Grant unprivileged user rights to see the output of echo|format but not modify disks

anyone have any idea how do to this with auth_attr? I suspect if I grant him solaris.device.:RO::Device Allocation::help=DevAllocHeader.html that will work but I'm unsure. Just looking for a second opinion. (10 Replies)
Discussion started by: os2mac
10 Replies

2. Shell Programming and Scripting

modify ls -l (long listing format output) strictly using SED only straightforward goalhard 4 me doh

Below is a sample out of ls -l which I would like to rearrange or modify by field numbers for example I successfully managed to disect using simple paragraph however for ls -l I can't divide the rows or fields by field number. Successful modification by fields using SED sample: $ sed -e... (1 Reply)
Discussion started by: wolf@=NK
1 Replies

3. Shell Programming and Scripting

Modify a perl line to parse out and output to another format

Hey there... I am looking for a way to take the below contents ( small excerpt) of this file called PTR.csv ptrrecord,,,,,,False,,,302400,default... (6 Replies)
Discussion started by: richsark
6 Replies

4. Shell Programming and Scripting

modify one column

Hi, I have an output that looks unusual and it is very large so I cannot do it manually. Basically it looks like this: U >c93 57866 R U >c38 66265 R U >c261 80401 R U >c169 12250 R U >c348 2661 F U >c425 38762 R U >c351 44504 R U >c421 8212 F U >c467 3648 F U >c84 33028 R... (6 Replies)
Discussion started by: phil_heath
6 Replies

5. AIX

find command modify the output

Hello All, I am new to this shell scripting , I wanted to modify the output of my find command such that it does not display the path but only file names , for example I am searching for the files which are modified in the last 24 hours which is find /usr/monitor/text/ -type f -mtime... (3 Replies)
Discussion started by: raokl
3 Replies

6. Shell Programming and Scripting

Need help with a sh script to spool directory and modify the output (Oracle cnt file)

Hi, I'm creating a shell script to dynamically create a recreate controlfile for an Oracle database. I need to read a cold backup file system, and make some changes to these files. Let's say for argument sake the directory name is /ebsprod_c/oradata and it looks like this:... (6 Replies)
Discussion started by: exm
6 Replies

7. Shell Programming and Scripting

Modify a file

Hi all Can anyone suggest me a good solution ? My requirement is as follows I have a plain text file similar to this... sending data to 0003345234 here is the output... ,.......... ........... ....... sending data to 00033452ab here is the output... ,.......... ........... .... (5 Replies)
Discussion started by: ./
5 Replies

8. Shell Programming and Scripting

how to modify the value of the variable

Hi I have a variable which holds full path to the file, for example z=/bb/data3/ I need to remove the extension .new so it would look like z=/bb/data3/f4222pdb.dta Is there a command to do this? This variable is used in the "for" loop later. I am in ksh. Thanks a lot -A (4 Replies)
Discussion started by: aoussenko
4 Replies

9. Shell Programming and Scripting

how can i add/modify filename after output?

Hi All, I have a script to convert a file and output the filename with "_output", however it not work. Can help? echo Please input list file name: read listn for file in `cat $listn.txt` do convert $file > $file_output Thanks all!! (3 Replies)
Discussion started by: happyv
3 Replies

10. Shell Programming and Scripting

modify a file

I'm a new member of the forum, I had this new generate file since I use 'grep' and 'awk', what I want to do is get rid off the all 0s before the numbers, is there any one who could help me to figure it out? Thanks a lot! yun 0000000029 000q7472 2002/03/01 0000000030 000q7472 2002/03/01 ... (2 Replies)
Discussion started by: yxiao
2 Replies

Featured Tech Videos