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 2916
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 is not clear at all for me.
Can python run with a posix C compiler and minix or something like that ?
Thanks
|
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 server site?
Can we develop client application on VS.Net and put database on Unix environment? Can Web Services be deployed onto Unix environment
Any advice?
|
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 with a team that has been tasked with providing
scientific computing support for national and international research
and development projects in Bioinformatics, Genomics, and Proteomics.
Our clients produce some of the largest and most rapidly...
|
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 functions
Just quoting an example below:
void main()
| |
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 Unix, for example,
open(), close(), read(), write(), lseek() ...
Which set of functions is more suitable for I/O task, C library version
or Unix version?
Thank you
|
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 have a look and make use of it.
|
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 which I mean here.
Just for a moment, let's just take one definition for one of the
|
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 (scripts) to get run in unix while using
preferably vb.net or c# applications run in windows. So far all the unix
aplications are started manualy through the command window. Files are sent
using FTP. We have XceedFTP client to send files to unix from...
|
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 got errors of Failed to
open file ./outdir/mytestout.txt. Below is the code:
#include <stdio.h>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |