Sponsored Content
Top Forums Shell Programming and Scripting Display combination of 4 field uniqe record and along with concatenate 5th and 6th field. Post 302957945 by udhal on Friday 16th of October 2015 06:10:11 PM
Old 10-16-2015
Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table
Code:
ACN|NAME|CITY|CTY|NO1|NO2
115|AKKK|ASH|IND|10|15
115|AKKK|ASH|IND|20|20
115|AKKK|ASH|IND|30|35
115|AKKK|ASH|IND|30|35
112|ABC|FL|USA|15|15
112|ABC|FL|USA|25|20
112|ABC|FL|USA|25|45

i have written shell script using cut command
and awk programming getting error correct it and add header we can use echo for header is it other way display the header

Please ignore space consider | separtor
Code:
sed -n '2,$p' test > test1
for j in `cat test1|cut -d "|" -f1|uniq`
do
a=" "
b=" "
for i in `cat test1`
do
  if [ `echo $i|cut -d "|" -f1` -eq $j ]; then
 no1=`echo $i|grep "$j"|cut -d "|" -f5`
 no1=`echo $i|grep "$j"|cut -d "|" -f6`
 acn=`echo $i|cut -d "|" -f1`
 name=`echo $i|cut -d "|" -f2`
 city=`echo $i|cut -d "|" -f3`
cnt=`echo $i|cut -d "|" -f4`
a=$a$no1"|"
b=$b$no2"|"
fi
done
echo $acn "|" $name "|" $city "|" $cnt "|" $a "|" $b
done
-------
awk '
  {print $1 FS $2 FS $3
             
        }
        {IX=$1 FS $2 FS $3 
         MAX[IX]=MAX[IX] DL[IX] $4
         MIN[IX]=MIN[IX] DL[IX] $5
         DL[IX]="|"
        }
END     {for (m in MAX) print m, MAX[m], MIN[m]}
' FS="|" file

below output should be display
First 4 filed will be display unique and last two field should be concatenate(no1)$(no2)
Code:
115|AKKK|ASH|IND|10|20|30|30|15|20|35|35
112|ABC|FL|USA|15|25|25|15|20|45

Appreciate ur replay

Last edited by Corona688; 10-16-2015 at 08:01 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Retrieve 5th Field to Last Field !!

I have a script which retrieves certain fields from a text file using awk. The delimiter used is white space. cat /home/eis/boss/OPS|while read LINE do crdno=`echo $LINE | awk '{print $1}'` atm=`echo $LINE | awk '{print $2}'` seq=`echo $LINE | awk '{print $3}'` amount=`echo $LINE | awk... (3 Replies)
Discussion started by: jobbyjoseph
3 Replies

2. Shell Programming and Scripting

get a field from a record

I have a file as: A,B,C,D,E G,H,I,J,K I need to find if fourth field is blank or has a space and print that line to other file. I tried using awk but am not getting the desired result. Pls help. (6 Replies)
Discussion started by: praveenK_Dudala
6 Replies

3. Shell Programming and Scripting

Get 4 character each from 2 different fields concatenate and add as a new field

Hi, I have a huge text file. It looks like abcde bangalo country 12345 lastfield i want to get first 3 characters from field1 and first 3 characters from field 2 and insert the result as a new field. example the result should be: abcde bangalo abcban country 12345 lastfield Please... (4 Replies)
Discussion started by: ajithshankar@ho
4 Replies

4. Shell Programming and Scripting

concatenate consecutive field values

Hi, I have a file like this A Bob A Sam A John B David C Paul C Sandra If the consecutive field values in column one is same, then concatenate the corresponding strings. So, I need an output like this, A Bob_Sam_John B David C Paul_Sandra I usually work with excel but... (3 Replies)
Discussion started by: polsum
3 Replies

5. Shell Programming and Scripting

Get last field specific record

i have file A as below contents --------------------------- Use descriptive thread titles when posting. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". For example, do not post questions For example, do not deliminated. output file as below:... (2 Replies)
Discussion started by: ANSHUMAN1983
2 Replies

6. Shell Programming and Scripting

Concatenate last field values for all occurences

Hello all, Maybe you can help me with an awk script to get what I need. I have the input file with format below: REQUEST|79023787741690|738227864597|985 REQUEST|79024002151717|738229423534|985 REQUEST|79024002151717|738229423534|*985 NDS-REQUEST|79024002151717|738229423534 ... (4 Replies)
Discussion started by: Ophiuchus
4 Replies

7. UNIX for Dummies Questions & Answers

How to sort the 6th field of tab delimited files?

Here's a sample of the data: NAME BIRTHDAY SEX LOCATION AGE ID Jim 05/11/1986 M Japan 27 86 Rei 08/25/1990 F Korea 24 33 Jane 02/24/1985 F India 29 78 I've been trying to sort files using the... (8 Replies)
Discussion started by: maihani
8 Replies

8. Shell Programming and Scripting

How to remove alphabets/special characters/space in the 5th field of a tab delimited file?

Thank you for 4 looking this post. We have a tab delimited file where we are facing problem in a lot of funny character. I have tried using awk but failed that is not working. In the 5th field ID which is supposed to be a integer only of that file, we are getting corrupted data as below. I... (12 Replies)
Discussion started by: Srithar
12 Replies

9. Shell Programming and Scripting

Trying to get 5th field from ls -l output

Bash Shell/Oracle Linux 6.4 Following is an ls -lh output. Files which are equal to or higher than 1Gigabytes will displayed with G in the 5th column of the output. I am trying to find all files which are equal to or higher than 1G File sizes are shown in the 5th column. So, I tried cut -d'... (7 Replies)
Discussion started by: John K
7 Replies

10. UNIX for Dummies Questions & Answers

Display latest record from file based on multiple columns combination

I have requirement to print latest record from file based on multiple columns combination. EWAPE EW1SLE0000 EW1SOMU01 ABORTED 03/16/2015 100004 03/16/2015 100005 001 EWAPE EW1SLE0000 EW1SOMU01 ABORTED 03/18/2015 140003 03/18/2015 140004 001 EWAPE EW1SLE0000 EW1SOMU01 ABORTED 03/18/2015 220006... (1 Reply)
Discussion started by: tmalik79
1 Replies
echo(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.10 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 05:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy