File Concatenation in a format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Concatenation in a format
# 8  
Old 02-26-2014
Closer to the requirement:
Code:
awk 'FNR==1{p=$0; $51=$0=x; $0=$0 ORS FILENAME ":" ORS p}1' OFS="\= " file*

# 9  
Old 02-26-2014
Thanks it looks fine but couldnt understand it totally. Maybe if I will then i can increase the ====
# 10  
Old 02-26-2014
You may try on bash

Code:
#!/bin/bash


printme(){
		# change here whatever you want
		echo $(printf '=%.0s' {1..75})
	 }

for file in *.txt ; do
		# print something n times
		printme
		
		# Name of your file
		echo "$file :"
		
		# content of your file
		cat  $file

		# print something n times
		printme
done

run like this on terminal bash yourscriptname not sh yourscriptname, this will not work with sh I think
# 11  
Old 02-26-2014
Quote:
Originally Posted by ankur328
Thanks it looks fine but couldnt understand it totally. Maybe if I will then i can increase the ====
Sure:

Code:
awk '                                                    
  FNR==1{                           # If we are at the first line of a new file
    p=$0                            # Save the line in variable  "p"
    $51=$0=x                        # make the line empty ($0=x) and als make $51 empty ($51=x). By doing so 50 other empty fields are created with the value of OFS in between, which is set to "\ "
    $0=$0 ORS FILENAME ":" ORS p    # set the current line to $0 which now contains the 50 = characters and ORS which is set to '\n' and the filename of the file, another '\n' and the original line content that was saved in variable "p"
  }
  1                                 # print the record
' OFS="\= " file*                   # set OFS to "\= " and specify which files to read

So by changing $51 to $61, it will print 60 =-signs
# 12  
Old 02-26-2014
Bit lengthy awk approach : you may try,

Code:
awk 'BEGIN{
		while(++i<75)
		text = text "="
	  }
    FNR==1{
		print text RS FILENAME " :"
          }1
       END{
                print text
          }' *.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Concatenation of multiple files based on file pattern

Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR" "Report.Dddmmyy.Thhmiss.ACCD" "Report.Dddmmyy.Thhmiss.BCCD" "Report.Dddmmyy.Thhmiss.CCCD"... (1 Reply)
Discussion started by: Jesshelle David
1 Replies

2. Shell Programming and Scripting

Issue in Concatenation/Joining of lines in a dynamically generated file

Hi, I have a file containing many records delimited by pipe (|). Each record should contain 17 columnns/fields. there are some fields having fields less than 17.So i am extracting those records to a file using the below command awk 'BEGIN {FS="|"} NF !=17 {print}' feedfile.txt... (8 Replies)
Discussion started by: TomG
8 Replies

3. Shell Programming and Scripting

File concatenation

awk '{$2=$2":"$8"-"$3;$3=$NF;$4=$NF="";print $0 | $10=$10":"$8"-"$18;$11=$NF;$12=$NF="";print $0 }' design.txt Trying to concatenate specific fields in a spreadsheet and the others remain unchanged. I attached an excel spreadsheet (all the data comes from a design.txt), but I put an example... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Erroneous file concatenation.

I have more than one files in a directory , namely GLOW_OUT.txt FIELD_OUT.txt BASE_OUT.txt ... SHOW_OUT.txt What I wanted to do is to I am working in Korn Shell What I did was : for file in <directory_name>/*.* ;do cat $file | grep -v '^$' >> temp_file rm $file done ... (7 Replies)
Discussion started by: kumarjt
7 Replies

5. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

6. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

7. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

8. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies

9. UNIX for Dummies Questions & Answers

File Concatenation

Hi, I want to write a generic shell script, which can concatenate n number of files passed as parameter ;to an output file which is again a parameter Example catfl.sh outfl.txt a.txt b.txt c.txt (3 files to be concatenated into a file outfl.txt) catfl.sh outfl.txt a.txt b.txt(2 files to be... (3 Replies)
Discussion started by: samit_9999
3 Replies

10. Shell Programming and Scripting

File concatenation problem

I have written a script to find particular text files created within the last 24 hours and concatenate them all into a single concat.txt file. The problem that I am running into is that the last line of the text files do not terminate with <CR><LF> characters (as do all the other lines in each... (3 Replies)
Discussion started by: jvander
3 Replies
Login or Register to Ask a Question