473,320 Members | 1,945 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,320 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 2076
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.