General :: Append Text With AWK Or SED?
Mar 19, 2010
I'm doing an assignment for school, and while we have not yet learned regular expressions, my teacher would like us to use AWK to append text to certain lines in a file. What we've had to do is creating a listing of all links and directories in the /etc folder and place them in a text file. From this, we were to cut the first field (Permissions) and the ninth field (filename) and create another text file. Now the part that I'm struggling with is this and I'm not sure if I should be using sed or awk. We're supposed to ADD the text "DIR" to the beginning of any line that is a directory, and "LNK" to any that is a link, like so:
DIRdrwxr-xr-x redhat-lsb
DIRdrwxr-xr-x rhgb
LNKlrwxrwxrwx rnDIRc.key
DIRdrwxr-xr-x rpm
Obviously, I realize that the first character in the permissions denotes what sort of file it is, hence when I created my text file I used
ls -l | grep "^d" > file.txt
and
ls -l | grep "^l" >> file.txt
I'd like to learn how to properly do this, but struggling through pages on the internet hasn't been helping, nor has the --help command. Therefore, while I would like the answer, I'd also like to know what the heck I'm doing For example, I know I could delete lines with regex using d/[STUFF I WANT TO DELETE]/g (To get rid of all occurences) and I can substitute using s/foo/bar But I'm unaware of anyway to ADD text upon certain occurences, let alone two different circumstances.
View 6 Replies
ADVERTISEMENT
Jan 15, 2010
may be an advanced question but I need to know how to do this. Here at work I am in charge of recruiting and we have about 1,000 resumes in already. All of the resumes are in a .pdf format. I need to rename every .pdf in the following format:{firstnameLastname}.pdfThe only way I know how to do this is to convert all the .pdf files to text, extract the name out of the first few lines of text, import into excel, and then use VBA to rename the files in mass:Here is my logic so far:~Deskop/a = houses all the .pdfresumesOpen terminal: Code: cd ~/Desktop/afor f in *.pdf; do pdftotext -raw $f; done That will convert all of the preceding resumes into text filesNow I would like to append the name of the text file into the last line of the text file. So, for example, for Resume1.txt, I want to append "Resume1.txt" to the last line within Resume1.txt. So after I run the command I open Resume1.txt and on the last line within I want to see "Resume1.txt" on the last line, at the end of the resume.How can I do this? I would like to use a loop and have the terminal append the filename to the body of the text file until all of the have been appended.
View 1 Replies
View Related
Nov 5, 2010
Using sed, I am trying to append four commas ',,,,' at the end of lines containing the pattern 'Response' in a text file with lines such as these:
6,Pulse,50,254968,14886,NA,,,,
7,Picture,8,265157,0,1,15045,2,0,15000
7,Response,1,271553,6396,1
7,Pulse,50,274969,9812,NA,,,,
8,Picture,1,290232,0,1,15045,2,0,15000
8,Pulse,50,294969,4737,NA,,,,
[Code].....
View 1 Replies
View Related
Dec 2, 2009
I want to append some text to the file, files are mostly big, more then 100 mb. I found the cat command, so I can create a new txt file and then append it to the original file with it. Two questions:
1. Can I append text to the file instead of creating the new file and then appending it to the original file? eg:
Code:
cat file.avi "some text" > newfile.avi
2. cat takes several seconds to execute the merging files together, it seems that it is reading the original file first, is there a way skip the reading and just append the file?
View 3 Replies
View Related
Nov 6, 2010
Say I have a text file like:
Code:
1
3
4
How would I use ksh to put the number '2' into the second line of that file?Okay it's not bash, it's ksh because this computer is OpenBSD
View 14 Replies
View Related
Jan 14, 2010
I am trying to append text to the beginning of a file. This is what I have so far.
Code:
date_default_timezone_set('America/Chicago');
$date=date("m-d-Y g:i:s a");
[code]....
View 7 Replies
View Related
Aug 30, 2010
How do you append text to an entry in an existing file? For example, lets say I have a file called "env.logon" in /home/myself/bin that contains the following text:
PATH=/bin:/sbin If I wanted to add, via command line, ":/usr/bin:/usr/sbin" to the PATH= and I
used the "echo" command (echo "PATH=:/usr/bin:/usr/sbin) it would create a second entry and my file would look like:
PATH=/bin:/sbin
PATH=:/usr/bin:/usr/sbin
What I want is for it to look like:
PATH=/bin:/sbin:/usr/bin:/usr/sbin
Is there a way to get this result via command line?
View 3 Replies
View Related
Apr 15, 2009
I am thinking of appending something to each line in a text file with Java. I prefer not write a new file with content appended from the old one.That 'something' would probably be Time Stamp when the file is created (which is same for each line).I am not sure Java provide some easy way for it or not
View 3 Replies
View Related
Mar 16, 2010
So I have file which looks something like this:
cat .opera/operaprefs.ini
Code:
[User Prefs]
Language Files Directory=
[code]...
View 1 Replies
View Related
Mar 11, 2010
if you execute :
#!/bin/bash
echo "some textstring" >> logfile.txt
then the string "some textstring " will be APPENDED to logfile.txt Is there a redirect way that in stead of appended, the string will be INSERTED at the top of the logfile.txt file ? If this cannot be done by redirecting, what would be the best way to insert the test-string at the top of the logfile ?
View 2 Replies
View Related
Oct 7, 2009
I know similar questions have been asked before but I cannot seem to get it to work.I have a file file.something.nhMMYY that i need to ftp (MMYY being Month and Year)I want to add something into the script to auto-magically insert the MMYY.
View 8 Replies
View Related
Aug 24, 2010
the query is ||| how to append a char | string |||
#!/bin/bash
echo -n "one""two""three"
#END
above method is working well but below method is not working ?
#!/bin/bash
one=one
two=two
three=three
echo -n $one$two$three
#END
View 5 Replies
View Related
Apr 9, 2010
i just want to create a folder with current time.
For example.
foldername_09042010 How do i modify mkdir or write script to do this?
View 6 Replies
View Related
Feb 12, 2011
Greetings, I want to automatically append flags to certain commands. For example, when I type:
ls
at the prompt, I want the
-la
flags automatically appended without me having to type:
ls -la
View 2 Replies
View Related
Jun 20, 2011
we have centos and a win2k8 server. Our pos system is on the centos server. I created a HOST (A) record on win2k8. so users don't have to remember the ip address of the centos server.so i created a friendly name like URL... and the POS web page will be loaded.but my questions is it possible to configure the centos to automatically append the port number if the user type URL... will be auto added at the end of it.
View 3 Replies
View Related
Nov 28, 2010
Can you please let me know how can i append # in the begining of each line Based on a a search string lile /^8282##8282/gc
View 1 Replies
View Related
Feb 21, 2011
I have a existing zipped file , I want to use gzip command to append some files to it , I tried man gzip but can't find the key word "append" , can advise how can I do it ?
View 1 Replies
View Related
Aug 22, 2009
eed to make a script to append a line to the bottom of multiple files (only certain files, but 100's spread over directories).Doing a find replace inside multiple files is easy, I use the followingfind /base/dir -name "*.txt" -exec perl -pi -w -e 's/FIND/REPLACE/g;' {} ;So I tried doing the followingfind /base/dir -name "*.txt" -exec echo "Append this" >> {} ;However this just appends all the text into a file called "{}". Whereas {} should be replaced with each file that's found.
View 1 Replies
View Related
Nov 22, 2010
I wanted to be as clear as possible. I have to add hundreds of new servers to hundreds of configuration files in Nagios. Here is a sample structure:
servers.txt has:
SERVER3
SERVER4
[code]....
View 10 Replies
View Related
Jul 17, 2009
I was trying to install GTK+-2.8.20, so I installed it's necessary dependencies in this order:
pkg-config-0.23
glib-2.20.4
pango-1.24.4
jpeg library
tiff library
cairo
And I was about to install the last dependency: ATK (Accessability Toolkit).I opened the Archive Manager to extract the "atk-1.26.0.tar.gz" file (yes, I'm still switching from Windows so I'm fond of GUI), but I noticed all the text in that window was boxes, like the □ type box for every letter of text.So instead I thought it wouldn't be a big deal, because the terminal and regular windows weren't screwed up.I opened a text file in gedit (reference to commands in terminal, such as how to extract files via terminal), but yet again all of the text was □-like boxes.
View 2 Replies
View Related
Apr 21, 2010
Currently, when I'm searching text in files of my PHP project, I use this line :
Code:
grep -r 'myTextToFind' *
But now, I would like to search only in ".lang" files. How can I do that ?
View 7 Replies
View Related
Oct 28, 2010
EDIT1: I should note that I was trying to do this in PERL, not sure if other alternatives are more simple?EDIT2: I should note that for text file 3 (reference), it's a long list of MANY cnp_id values and their corresponoding chr, start, and end values. So, the code will have to take the cnp_id from text file 1 and/or 2 and search through textfile 3 (reference) to match on the cnp_id and then take the corresponding chr, start, and end values and add to the relevant line in the output.EDIT3: Sorry, I should mention that the text file entries are all tab-delimited.I have 3 text files:File 1:Columns represent sample IDs (sample_id) and rows represent CNP IDs (cnp_id). Cells represents the confidence level (confidence) for each sample and CNP.Quote:
cnp_idP5E6_SNP6.0_JHP5_010408.CELP5E11reh_SNP6.0_JHP5_011808.CELP7C7_SNP6.0_JHP7_021208.CEL ... etc.
CNP100.0044798340.0027929510.00305613
[code]...
View 6 Replies
View Related
Jul 3, 2009
I am using openSUSE 10.3.When I install software from tarball then to record time required I send output of date to beg.txt(when installation begins) and end.txt (when installation finishes).How can I append output of date to a file so I don't need two files?
View 4 Replies
View Related
Feb 19, 2010
I have to modify formsweb.cfg file in Oracle IAS.
Problem description
In formsweb.cfg file are two lines with labels archive_jini= and archive= at the beginning of line. After equal sign (=) is row of filenames of java archives delimited by coma(,). When I insert a new jar file in java directory, I have to append the very same name of jar file to both lines if that name is not yet present.
Example snippet from formsweb.cfg
View 2 Replies
View Related
Feb 12, 2011
I want to append at a new line if the old line is non empty. so it would be something like
Code:
1
2
3//dont add here
Code:
1
2
3
//add here
but if sometimes there could be extra empty line, then add at the empty line. So the script needs to detect whether or not the last line is empty. i figured out the symbol for a new line pattern is ^ so it would probably be sed "a^stuff here"is this right? but i dont seem to get the right result
View 12 Replies
View Related
Aug 10, 2010
The s means substitute
The $ in this particular regex (regular expression) means end of the line.
The ; is what you're subbing. This works fine and well, but what if you want to append a / at the end of the line?
sed 's/$///' filename doesn't work.
View 1 Replies
View Related
Sep 20, 2009
I'm having problems completing my school exercises with awk.
Heres the desired outcome:
Code:
./my_awk 2
ACG GAG ATT AGG AGG ATC CCA CCA
CAC AGG ACG GAG ATT AGG AGG ATC
So it generates data in group of threes, 8 groups per row and prints it. My problem is that I can't seem to get awk to append stuff to string so I could print it nicely to screen. It just prints empty lines per the parameter given to it.
Heres my code so far:
Code:
#!/bin/sh
awk -v rows=$1 '
BEGIN {
[code]....
View 2 Replies
View Related
Jan 29, 2011
What I am trying to achive is the editing of /etc/ssh/sshd_config I have the line
Code: AllowUsers usera userb
And I want to be able to append to the end of this line from a bash script.I have muddled together from other sites and got the following:-
Code: sed -e "s/^AllowUsers/� userc/" -i /etc/ssh/sshd_config
But this appears to add userc directly after AllowUsers and not after userb
View 2 Replies
View Related
Sep 12, 2009
Is there a way to specify append only permissions for a file?
View 2 Replies
View Related
Nov 29, 2010
Even though I've set up HTTPS to be trusted, it still blocks my school's https site: "mnsu.edu/eservices" same with SAMBA and SSH.
If enter the GUI and authenticate as root, change anything and apply, then exit: it works fine and so does SAMBA. However, after restarting, everything stops working again.
yet secure firewall configuration that doesn't require any login or headaches.
View 6 Replies
View Related