LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-28-2006, 01:40 AM   #1
sailu_mvn
Member
 
Registered: Sep 2004
Location: Hyderabad
Distribution: FEDORA,REDHAT,HOST
Posts: 440
Blog Entries: 1

Rep: Reputation: 30
join files using shell script


I have 3 files that are to be joined. Can anybody tell me how to stat writing a shell script?

And one more thing. In a file if at some point if i need to insert some text, how to do it.

For eg, a file called a.txt has at somepoint "NOTHING CAN HAPPEN" line. After that if i want to insert a paragraph, can i do that?
 
Old 07-28-2006, 01:43 AM   #2
crazyjimbo
Member
 
Registered: Mar 2006
Location: Edinburgh
Distribution: Debian Etch, Gentoo
Posts: 90

Rep: Reputation: 16
To join files, use:

Code:
cat inputfile1 inputfile2 inputfile3 > outputfile
 
Old 07-28-2006, 01:51 AM   #3
sailu_mvn
Member
 
Registered: Sep 2004
Location: Hyderabad
Distribution: FEDORA,REDHAT,HOST
Posts: 440

Original Poster
Blog Entries: 1

Rep: Reputation: 30
yeah i know it
if i have a file and i have to insert a paragraph at some articular localtion say line number 45
How to do it
 
Old 07-28-2006, 02:02 AM   #4
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
This will make a backup of the original file:
Code:
sed -i.bak -e'45,s/^/your new text here\n/' your_filename
 
Old 07-28-2006, 02:05 AM   #5
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
line_number=$(cat f1 |wc -l);
head -45 f1; cat f2; tail -$((line_number-45)) f1;
 
Old 07-28-2006, 02:13 AM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
well we meet again raskin.

to sailu_mvn you can try my script

Code:
#!/bin/bash

FILE=
INJECT=
LINENO=

{
	cat "$FILE" | sed -n 1,$((LINENO - 1))p
	cat "$INJECT"
	cat "$FILE" | sed -n ${LINENO},\$p
} > .tmp

cat .tmp > "$FILE"
rm .tmp
if something's wrong just try to fix it. it's easy to get its idea.

regards
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to remove backup ~ files hallamigo Linux - General 3 09-13-2010 03:47 PM
shell script for reading of configuration files nhydra Programming 2 06-13-2006 03:15 AM
Renaming files in a shell script Mike_the_Man Programming 7 04-17-2006 01:56 PM
put files in the shell script.... Tails1984 Programming 1 02-17-2006 02:33 PM
Shell Script: Reading Pdf files funkymunky Programming 8 06-18-2004 03:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration