hiya guys, i am trying to learn unix and i am sort of stuck in couple of questions, which i was hoping to get some help on.
1- i have created a file using the follwoing script: -
-
#!/bin/bash
-
ls -l > cust1
-
ls -x >> cust1
-
-
echo "The script has been run"
-
-
wc -l cust1 >> cust1
-
-
echo "The total number of words has been added to the file"
-
-
basically what i need to learn how to do is how can i append a text to begining, middle and end of the file.
eg: i would like to add : "Required information" to the start, midle and end of the file.
I have also been told i cant use SED or AWK.
Any help or pointer would be great.
thx in advance
Keyvan.
3 2898
hiya guys, i am trying to learn unix and i am sort of stuck in couple of questions, which i was hoping to get some help on.
1- i have created a file using the follwoing script: -
-
#!/bin/bash
-
ls -l > cust1
-
ls -x >> cust1
-
-
echo "The script has been run"
-
-
wc -l cust1 >> cust1
-
-
echo "The total number of words has been added to the file"
-
-
basically what i need to learn how to do is how can i append a text to begining, middle and end of the file.
eg: i would like to add : "Required information" to the start, midle and end of the file.
I have also been told i cant use SED or AWK.
Any help or pointer would be great.
thx in advance
Keyvan.
this seems like homework. hint: you can use cat,split,>>
this seems like homework. hint: you can use cat,split,>>
it is and its driving me insane, but so far i have achieved this: -
-
#!/bin/bash
-
-
rm -Rf $1
-
ls -l > cust1
-
-
echo "script done"
-
-
cp cust1 temp.file
-
-
echo "Following infor blah blah" > temp2.file
-
-
-
cat temp2.file >> temp.file
-
-
cat temp.file >> cust1
-
-
rm temp2.file
-
-
rm temp.file
-
-
cat cust1
-
-
-
Problem is i need echo "Following infor blah blah" on top of the file and currently is appended at the bottom of the page. Any idea how can i do that?
Keyvan
to put a string on top of file without sed/awk, you just make a temp file with the string inside. Then use the cat command to append to the file -
# echo "thestringtoputontop" > temp
-
# cat thefile >> temp
-
# mv temp thefile
-
to put the string in middle with sed/awk. here's a crude way. -
# linecount=$(wc -l file)
-
# echo ${linecount%file}
-
6
-
# half=$(echo "${linecount%file}/2" | bc) #this will divide your file into half
-
# echo $half
-
3
-
# echo "string" > temp
-
# split -l $half file #this will produce files xaa,xab
-
# cat temp >> xaa
-
# cat xab >> xaa
-
# mv xaa file
-
to put string at end of file, just use the >> operator, or the usual cat.
Of course there are other ways to do all these, but this is just a crude example
Sign in to post your reply or Sign up for a free account.
Similar topics
by: RosalieM |
last post by:
I would like to understand what python needs to work on unix.
And to understand how i can make it smalest possible?
I dont understand at all setup.
I searched in python.org and in sources but it...
|
by: Jonathan |
last post by:
Hi there
We are to make the decision on whether to choose .Net or J2EE. One of the questions my client asked is that, can we run the .Net application on Unix and Unix based database systems on...
|
by: abhi |
last post by:
Hello,
My name is Abhilash and I am recruiting for an experienced
Bioinformatics Programmer. This opportunity is permanent, full-time,
and on site in Bethesda/Rockville, MD.
The opportunity is...
|
by: Alan |
last post by:
Is anyone know the equivalent term used for Dynamic Link Library (DLL)
in unix environment??
Thanks
Alan
|
by: fidlee |
last post by:
I dont know if this is the right place to ask this question.
i got this book "The C Odyssey. Unix - The Open, Boundless C"
It is a 1992 edition book
The book speaks of all the unix specific...
|
by: lovecreatesbeauty |
last post by:
In the C programming language, I/O operation functions are declared in
stdio.h, for example, fopen(), fclose(), fwrite(), fread(), fseek() ...
But another set of I/O functions are also defined in...
|
by: softwareengineer2006 |
last post by:
1000 C,C++,RDBMS,Unix,OS Interview Questions And Answers
I have listed over 1000 C,C++,RDBMS,Unix,OS questions and answers
in my website
http://www.geocities.com/online_learning_qa
So please...
|
by: Michael |
last post by:
Hi,
I'm having difficulty finding any previous discussion on this -- I
keep finding people either having problems calling os.exec(lepev), or
with using python's exec statement. Neither of...
|
by: Marcin Wiszowaty |
last post by:
Hello,
I work at a company that has 2 development enviroments. One Unix which i
dont know anything about and the othe vs.net 03 with MSSQL server 2000 for
db. How can i cause applications...
|
by: Hongyu |
last post by:
Dear all:
I am trying to write to a file with full directory name and file name
specified (./outdir/mytestout.txt where . is the current directory)
in
C programming language and under Unix, but...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |