Visit Our UNIX and Linux User Community


Cut Return and Join


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cut Return and Join
# 1  
Old 06-22-2002
Cut Return and Join

I have a file that has sporadic lines being split by a carriage return. I need to remove the carriage return and join the current line with the next (ctr +j). The line being split is not a consistent character length.

Below is a sample of my data:
=====================================
REQC#WH01#RQ2002-99075# #A#""# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # $
REQC#WH01#RQ2002-99076# #A#"1024693613^Doherrera^Doscar$
herr"# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # $
====================================

The second and third line should be on 1 line. The # character is being used as a delimiter

I appreciate any help

thanks
# 2  
Old 06-22-2002
I don't understand the problem well enough to offer a solution. We need a lot more explanation here.

If lines 1 - 3 should be one line and lines 4-6 should be the second and so on, this would be easy. But you say the splits are sporadic. How can we determine exactly which lines are to joined? I'm sure you understand exactly what (cnt +j) is supposed to mean. But I sure don't. We need to know everything that you know about the problem.

Or have you given up on an automated solution? Are you looking to do this manually via an editor?
# 3  
Old 06-22-2002
i supposed that you wanna get the following format:

111111111111111111111111
###################################
2222222222222222222222222222222

correct?
# 4  
Old 06-24-2002
Thanks for your replies.

Let me clarifiy. below is some sample data


1) abcdefghijklmnopqrstuvwxyz$
2) abcdefghijklmno$
3) pqrstuvwxyz$
4) abcdefghijklmnopqrstuvwxyz$

Lines 1 and 4 are as expexted in my data file. However, lines 2 and 3 are supposed to be on one line (line 2). But, because of a new line character in the middle of the line, the row is being split.

I need to devise a method to check my file where a newline character has split the line, remove the new line character, and the join (ctrl + J) lines 2 an 3 into line 2.

The new line character does not occure in the same character position. It does not occur with any line frequency. I've been trying to create a script using either sed or awk to resolve the problem.

This is something that needs to happen nightly and will not be a 1 time manual effort.
# 5  
Old 06-26-2002
In private email, the OP told me that any line that does not start with "REQC" must be joined with the line that precedes it. This is the kind of information that we need to tackle this problem. Here is a sed script that does just that...
Code:
#! /usr/bin/sed -nf
#
#
${s/^REQC/REQC/
t final
H
b found
: final
x
s/\n//g
p
x
p
b
}
1{h
d
}
s/^REQC/REQC/
t found
H
b
: found
x
s/\n//g
p

Please take the time to define your problem carefully. We can't solve problems that we don't understand.
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #320
Difficulty: Medium
Intel created the first consumer 64-bit processor.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join, merge, fill NULL the void columns of multiples files like sql "LEFT JOIN" by using awk

Hello, This post is already here but want to do this with another way Merge multiples files with multiples duplicates keys by filling "NULL" the void columns for anothers joinning files file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: 1|123|jojo 1|NULL|bibi... (2 Replies)
Discussion started by: yjacknewton
2 Replies

2. Shell Programming and Scripting

Return: can only `return' from a function or sourced script

Not sure where the problem is. I can run the script without any issue using the following command. . /opt/app/scripts/cdc_migration.sh But it fails with the below error when I try it this way /opt/app/scripts/cdc_migration.sh /opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies

3. UNIX for Dummies Questions & Answers

How to use the the join command to join multiple files by a common column

Hi, I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column). I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies

4. UNIX for Dummies Questions & Answers

how to join two files using "Join" command with one common field in this problem?

file1: Toronto:12439755:1076359:July 1, 1867:6 Quebec City:7560592:1542056:July 1, 1867:5 Halifax:938134:55284:July 1, 1867:4 Fredericton:751400:72908:July 1, 1867:3 Winnipeg:1170300:647797:July 15, 1870:7 Victoria:4168123:944735:July 20, 1871:10 Charlottetown:137900:5660:July 1, 1873:2... (2 Replies)
Discussion started by: mindfreak
2 Replies

5. Shell Programming and Scripting

Using a combination of sort/cut/grep/awk/join/paste/sed

I have a file and need to only select users that have a shell of “/bin/bash” in the line using awk or sed please help (4 Replies)
Discussion started by: boyboy1212
4 Replies

6. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

7. Programming

sql,multiple join,outer join issue

example sql: select a.a1,b.b1,c.c1,d.d1,e.e1 from a left outer join b on a.x=b.x left outer join c on b.y=c.y left outer join d on d.z=a.z inner join a.t=e.t I know how single outer or inner join works in sql. But I don't really understand when there are multiple of them. can... (0 Replies)
Discussion started by: robbiezr
0 Replies

8. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

9. Shell Programming and Scripting

join (pls help on join command)

Hi, I am a new learner of join command. Some result really make me confused. Please kindly help me. input: file1: LEO oracle engineer 210375 P.Jones Office Runner ID897 L.Clip Personl Chief ID982 S.Round UNIX admin ID6 file2: Dept2C ID897 6 years Dept5Z ID982 1 year Dept3S ID6 2... (1 Reply)
Discussion started by: summer_cherry
1 Replies

Featured Tech Videos