Sponsored Content
Full Discussion: records in a line
Top Forums Shell Programming and Scripting records in a line Post 302357881 by varontron on Wednesday 30th of September 2009 11:08:13 PM
Old 10-01-2009
if you don't mind a trailing comma, you can do it in one line
Code:
tr "\n" "," < in > out

if not:
Code:
#!/bin/sh
touch out
LINECT=`cat in|wc -l`
COUNTER=1
while read line
do
  if [ ${COUNTER} -lt ${LINECT} ]
  then
     echo $line|tr "\n" "," >> out
  else
     echo $line >> out
  fi
  COUNTER=`expr $COUNTER + 1`
done < in


Last edited by varontron; 10-01-2009 at 12:17 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

delete records using line number(NR)

Hai I have a flat file which contains more than 6 crore lines or records. I want to delete only one line, using line number. For example I want to delete 414556 th line . How to do this using sed or awk command. thanks (3 Replies)
Discussion started by: tkbharani
3 Replies

2. Shell Programming and Scripting

Change a Char Multiple line records

Hi All i have a file that is to big for vi and is a multiple line record 3999||20090127163547796|196.46.162.250|1028|196.207.40.112|2152|00:0C:31:BB:25:5 4|00:00:0C:07:AC:06|655016000575511|05||3C65|0D029C1D|||00644B5A|||||||||||inter... (5 Replies)
Discussion started by: gseptember
5 Replies

3. Shell Programming and Scripting

how to delete records with the given line numbers

I have a file which has about 10000 records and I need to delete about 50 records from the file. I know line numbers and am using sed '134,1357,......d' filename > new file. It does not seem to be working. Please Advice (5 Replies)
Discussion started by: mad_man12
5 Replies

4. Shell Programming and Scripting

Singled line records

Hi, :cool: I´m new on this Linux groups and like to learn more, Right now, I´m working on a project (personal) and have a question fallowing problem I´m making a bash script to read many files and extract some fields and separate them according certain criteria, let say a have a big file... (4 Replies)
Discussion started by: Zopilota
4 Replies

5. Shell Programming and Scripting

Capturing multi-line records containing known value?

Some records in a file look like this, with any number of lines between start and end flags: /Start Some stuff Banana 1 Some more stuff End/ /Start Some stuff End/ /Start Some stuff Some more stuff Banana 2 End/ ...how would I process this file to find records containing the... (8 Replies)
Discussion started by: cs03dmj
8 Replies

6. Shell Programming and Scripting

Help to Add and Remove Records only from first line/last line

Hi, I need help with a maybe total simple issue but somehow I am not getting it. I am not able to etablish a sed or awk command which is adding to the first line in a text and removing only from the last line the ",". The file is looking like follow: TABLE1, TABLE2, . . . TABLE99,... (4 Replies)
Discussion started by: enjoy
4 Replies

7. HP-UX

Utmpd(1M) can't handle records with same line but different ids

For ddfa(7), telnetd(1M) needs to create user accounting database records with the same line (representing the remote side) but different ids (representing the pty that comes to be used for the connection), like line "telnet/ss10" with first id "tb" and then id "tf". Utmpd(1M) cannot handle... (1 Reply)
Discussion started by: madhurtripathi
1 Replies

8. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

9. Shell Programming and Scripting

Need the line number of failed records

Hi awk Gurus, I have file as below : file1.txt 7000,2,1,6 7001,2,1,7 7002,2,1,6 7003,1,2,1 file2.txt 7000,john,2,0,0,1,6 7000,john,2,0,0,1,7 7000,john,2,0,0,1,8 7000,john,2,0,0,1,9 7001,elen,2,0,0,1,7 7002,sami,2,0,0,1,6 7003,mike,1,0,0,2,1 (13 Replies)
Discussion started by: arunshankar.c
13 Replies

10. Shell Programming and Scripting

Creating duplicate records from a single line

Hi All, I would like to create a 1 million duplicate records from a single fixed length row. Is there a simple way to create this quickly in unix. I am using korn shell on the AIX OS. For ex, 100234 XHYSDDS SDSD OUPUT (1 million rows) 100234 XHYSDDS SDSD . . . 100234 XHYSDDS SDSD... (5 Replies)
Discussion started by: saratha14
5 Replies
line(1) 						      General Commands Manual							   line(1)

NAME
line - Reads one line from standard input SYNOPSIS
line STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: line: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None DESCRIPTION
The line command copies one line, up to and including a newline, from standard input and writes it to standard output. Use this command within a shell command file to read from your terminal. The line command always writes at least a newline character. NOTES
The line utility has no internationalization features and is marked LEGACY in XCU Issue 5. Use the read utility instead. EXIT STATUS
Success. End-of-File. EXAMPLES
To read a line from the keyboard and append it to a file, enter: echo 'Enter comments for the log:' echo ': c' line >>log This shell procedure displays the message: Enter comments for the log: It then reads a line of text from the keyboard and adds it to the end of the file log. The echo ': c' command displays a : (colon) prompt. See the echo command for information about the c escape sequence. SEE ALSO
Commands: echo(1), ksh(1), read(1), Bourne shell sh(1b), POSIX shell sh(1p) Functions: read(2) Standards: standards(5) line(1)
All times are GMT -4. The time now is 10:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy