473,408 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

marge line

test.text:-
--------
601215856422|COM|0|0|CD|1|3.99
601215868029|COM|0|0|CD|1|3.99
801472092322|COM|0|0|CD|2|10.98
802097013822|COM|0|0|CD|2|10.98
601215856422|MOM|0|0|CD|1|3.99
601215856422|RNO|0|0|CD|1|3.99
601215856422|SOM|0|0|CD|1|3.99

..........

I have to do
601215856422|COM|0|CD|1|3.99|MOM|0|CD|1|3.99|RNO|0 |CD|1|3.99
....

using shell script

pls help me.

thanks!
vaskar
Feb 28 '08 #1
8 2079
test.text:-
--------
601215856422|COM|0|0|CD|1|3.99
601215868029|COM|0|0|CD|1|3.99
801472092322|COM|0|0|CD|2|10.98
802097013822|COM|0|0|CD|2|10.98
601215856422|MOM|0|0|CD|1|3.99
601215856422|RNO|0|0|CD|1|3.99
601215856422|SOM|0|0|CD|1|3.99

..........

I have to do
601215856422|COM|0|CD|1|3.99|MOM|0|CD|1|3.99|RNO|0 |CD|1|3.99
....
The code is bit complicating but i have provided you flexibility to do a lot of things,I also believe there are a lot more simpler ways to do it

Expand|Select|Wrap|Line Numbers
  1. a=601215856422
  2. filelengthmain=`wc -l input.txt |cut -d ' ' -f1`
  3. val1=1
  4. val1=`expr $val1 + 0`
  5. for ((j=1; j<=$filelengthmain; j++))
  6. do
  7. ln=`head -$val1 input.txt|tail -1`
  8. val=`echo $ln | cut -d '|' -f 1`
  9. if test $a = $val
  10. then
  11. fvals[$val]=`echo $ln | grep -e $a |grep -v SOM | cut -d '|' -f 2-3,5-7`
  12. b=`echo $b"|"${fvals[$val]}`
  13. fi
  14. val1=`expr $val1 + 1`
  15. done
  16. echo $a$b
  17.  
Output :

601215856422|COM|0|CD|1|3.99|MOM|0|CD|1|3.99|RNO|0 |CD|1|3.99|
Apr 2 '08 #2
gpraghuram
1,275 Expert 1GB
You can use this script

Expand|Select|Wrap|Line Numbers
  1. FULL_LINE=""
  2.  
  3. while read LINE
  4. do
  5.   if [ "$FULL_LINE" == "" ]
  6.   then
  7.       FULL_LINE="$LINE"
  8.   else
  9.     FULL_LINE=$FULL_LINE"|"$LINE
  10.   fi
  11. done < "ip.txt" 
  12.  
  13. echo "FULL_LINE is : ${FULL_LINE}"
  14.  
  15.  
Raghuram
Apr 2 '08 #3
If I understand correctly:

Expand|Select|Wrap|Line Numbers
  1. awk '{ 
  2. for (f=2; f<=NF; f++)
  3.   if (f != 3)
  4.     x[$1] = x[$1] FS $f
  5. } END {
  6. for (k in x)
  7.   print k x[k]
  8. }' OFS='|' FS='|' file
Apr 2 '08 #4
oberon
14
Here is a one-liner for the same job:
Expand|Select|Wrap|Line Numbers
  1. cat test.text | echo -n $(awk {'print $0 "|"'}) | sed -e 's/\ *//g'
The -n is to remove newline, and the last sed is to remove a whitespace that would otherwise sneak in.
Apr 2 '08 #5
Thanks all!

601215856422|COM|0|0|CD|1|3.99
601215868029|COM|0|0|CD|1|3.99
801472092322|COM|0|0|CD|2|10.98
802097013822|COM|0|0|CD|2|10.98
601215856422|MOM|0|0|CD|1|3.99
601215856422|RNO|0|0|CD|1|3.99
601215856422|SOM|0|0|CD|1|3.99

but i have to do

601215856422|MOM|1|3.99|RNO|1|3.99|SOM|1|3.99|COM| 1|3.99
801472092322|COM|0|0|CD|2|10.98
601215868029|COM|0|0|CD|1|3.99
.....

the file size is very large nearly 91 MB.So it takes lot of time.But i have to do it with in 5 min.

Still i am trying to solve the problem.

please help me...
Apr 29 '08 #6
oberon
14
601215856422|MOM|1|3.99|RNO|1|3.99|SOM|1|3.99|COM| 1|3.99
801472092322|COM|0|0|CD|2|10.98
601215868029|COM|0|0|CD|1|3.99
Your last post didn't really clearify what you are looking for. If you could please add a few lines of explanation, then you would have a greater chance of getting the right answer.
Apr 29 '08 #7
i need concate all duplicate lines like

794051400123|COM|24|MOM|62|SOM|25|RNO|73
794051413727|COM|11||MOM|4|RNO|8
............

and save it another file..
Apr 30 '08 #8
gpraghuram
1,275 Expert 1GB
i need concate all duplicate lines like

794051400123|COM|24|MOM|62|SOM|25|RNO|73
794051413727|COM|11||MOM|4|RNO|8
............

and save it another file..

The first part of the string that is the 794051400123 is the token with which you find whether it is a duplicate token?

Raghuram
May 2 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: les_ander | last post by:
Hi, suppose I am reading lines from a file or stdin. I want to just "peek" in to the next line, and if it starts with a special character I want to break out of a for loop, other wise I want to...
7
by: jamait | last post by:
Hi all, I m trying to read in a text file into a datatable... Not sure on how to split up the information though, regex or substrings...? sample: Col1 Col2 ...
6
by: mary | last post by:
When we use string line; while (getline(in,line)) { out.write(line.c_str(),line.size()); out.put('\n'); } in.close();
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
2
by: sb Luis | last post by:
Hi, 1- I am going to marge contents of 3 RichTextBox (RTF) to one RTF string. Do you know any componet to make it simple? 2- Do you know a good RTF Editor and also a HTML Editor component in C# ....
3
by: Double Echo | last post by:
Hi all, I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. ...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
6
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to...
11
by: xdevel | last post by:
Hi, I don't understand option. if I write: #line 100 "file" I change file numeration to start to line 100 but what "file" ? any example?
19
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
This is an example of the data; 2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511) RX 74 bytes 2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.