473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

UNIX Questions

keyvanrahmadi
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/bin/bash
  3. ls  -l > cust1
  4. ls -x >> cust1
  5.  
  6. echo "The script has been run"
  7.  
  8. wc -l cust1 >> cust1
  9.  
  10. echo "The total number of words has been added to the file"
  11.  
  12.  
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.
Apr 15 '07 #1
3 2901
ghostdog74
511 Expert 256MB
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/bin/bash
  3. ls  -l > cust1
  4. ls -x >> cust1
  5.  
  6. echo "The script has been run"
  7.  
  8. wc -l cust1 >> cust1
  9.  
  10. echo "The total number of words has been added to the file"
  11.  
  12.  
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,>>
Apr 15 '07 #2
this seems like homework. hint: you can use cat,split,>>
it is and its driving me insane, but so far i have achieved this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/bin/bash
  3.  
  4. rm -Rf $1
  5. ls -l > cust1
  6.  
  7. echo "script done"
  8.  
  9. cp cust1 temp.file
  10.  
  11. echo "Following infor blah blah" > temp2.file
  12.  
  13.  
  14. cat temp2.file >> temp.file
  15.  
  16. cat temp.file >> cust1
  17.  
  18. rm temp2.file
  19.  
  20. rm temp.file
  21.  
  22. cat cust1
  23.  
  24.  
  25.  
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
Apr 16 '07 #3
ghostdog74
511 Expert 256MB
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
Expand|Select|Wrap|Line Numbers
  1. # echo "thestringtoputontop" > temp
  2. # cat thefile >> temp
  3. # mv temp thefile
  4.  
to put the string in middle with sed/awk. here's a crude way.
Expand|Select|Wrap|Line Numbers
  1. # linecount=$(wc -l file)
  2. # echo ${linecount%file}
  3. 6
  4. # half=$(echo "${linecount%file}/2" | bc) #this will divide your file into half
  5. # echo $half
  6. 3
  7. # echo "string" > temp
  8. # split -l $half file #this will produce files xaa,xab
  9. # cat temp >> xaa
  10. # cat xab >> xaa
  11. # mv xaa file
  12.  
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
Apr 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
1
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...
5
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...
4
by: Alan | last post by:
Is anyone know the equivalent term used for Dynamic Link Library (DLL) in unix environment?? Thanks Alan
9
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...
36
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...
1
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...
4
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...
1
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...
65
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.