Help in formating a txt file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in formating a txt file
# 1  
Old 09-21-2010
Help in formating a txt file

Pls help in formatting a txt file using shell scripting

Input file format:

Name priya 2010-09-21 10:43:49
TEXT ID 1
hi
TEXT ID 2
how
TEXT ID 3
r
TEXT ID 4
u

Output required:

name priya hi how r u

Last edited by bha148; 09-21-2010 at 09:44 AM..
# 2  
Old 09-21-2010
Code:
awk 'NR==1{printf $1 FS $2 FS;next} NR%2 {printf $0 FS}' infile

# 3  
Old 09-21-2010
hi thanks a lot

But pls help me if my input file is the below format:
Name priya 2010-09-21 10:43:49
TEXT ID 1
hi
TEXT ID 2
how
TEXT ID 3
r
TEXT ID 4
u
Name2 priya2 2010-09-21 10:43:49
TEXT ID 1
hi1
TEXT ID 2
how1
TEXT ID 3
r1

Output required:
name priya hi how r u
name2 priya2 hi1 how1 r1
# 4  
Old 09-21-2010
Code:
awk '/^Name/ {printf RS $1 FS $2 FS;next} !/^TEXT/ {printf $0 FS}' infile

# 5  
Old 09-22-2010
hi thanks again.
Pls do me one more favour.

Pls help in getting the output with seperator like below.

name: priya: hi: how: r: u:
name2: priya2: hi1: how1: r1:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File formating

I need to create a fixed width file based on the column lengths. lets assume I have six(this may be dynamic) fields each are of different length column1=6 #size of the column column2=3 column3=2 column4=3 column5=4 column6=5 I tried below code snippet but it is not working echo... (4 Replies)
Discussion started by: gvkumar25
4 Replies

2. UNIX for Beginners Questions & Answers

File formating help

Hi all, I am having the file below I need that as below Thanks, Arun (12 Replies)
Discussion started by: arunkumar_mca
12 Replies

3. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

4. Windows & DOS: Issues & Discussions

2 Questions: replace text in txt file, add text to end of txt file

so... Lets assume I have a text file. The text file contains multiple "#" symbols. I want to replace all thos "#"s with a STRING using DOS/Batch I want to add a certain TEXT to the end of each line. How can I do this WITHOUT aid of sed, grep or anything linux related ? (1 Reply)
Discussion started by: pasc
1 Replies

5. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

6. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

7. UNIX for Dummies Questions & Answers

Help in formating the txt file based on word match

Hi pls help in processing this file based on text id match if id not matches then column to be filled with "null" Input: Name priya 2010-09-21 10:43:49 TEXT ID 1 hi TEXT ID 2 how TEXT ID 3 r TEXT ID 4 u Name2 priya2 2010-09-21 10:43:49 TEXT ID 1 hi1 TEXT ID 2 how1... (2 Replies)
Discussion started by: bha148
2 Replies

8. UNIX for Dummies Questions & Answers

File formating help needed.

I have a file called vm.cfg . content of file. acpi = 1 apic = 1 builder = 'hvm' How would i write a script which will add boot = 'd' at 3rd line. For example. after running the script the file should be like below. acpi = 1 apic = 1 boot = 'd' builder = 'hvm' I dont want to... (3 Replies)
Discussion started by: pinga123
3 Replies

9. Shell Programming and Scripting

command to list .txt and .TXT file

Hi expersts, in my directory i have *.txt and *.TXT and *.TXT.log, *.txt.log I want list only .txt and .TXT files in one command... how to ?? //purple (1 Reply)
Discussion started by: thepurple
1 Replies

10. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my problem...so here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" abc@abc.com it works... (2 Replies)
Discussion started by: ash22
2 Replies
Login or Register to Ask a Question