I'm looking for a way to insert the number of lines in a file to the start of the aformentioned file. This should be simple but as I am not used to scripts in Linux, I am finding it tough going. I can find the number of lines in a file easily enough via
filesize=$(awk 'END {print NR}' $1)
but as for inserting this into the first line, i'm failing to do so. I've tried some of the other approaches on these forums but none so far have been able to do so.
I've tried:
sed '1i$filesize' $1
but sed i requires a string, not a variable so no go I've also tried:
but again with no luck as cat seems to need an input stream Just to recap, i want to insert a line at the start of a given file that holds the number of lines the original file has.
I'm a newbie on Linux and had to do something like this with the zip command:
My folder structure inside a zip file abc.zip is code...
It would move into abc.zip as folder3/textfile.txt (the hierarchy preserved) Also used a -j switch (help said it junked the path info and it did but) - it would move only into abc.zip and sit at the same level as folder1 and folder2 instead of replacing the textfile.txt within abc.zip/folder1
My question is - I want to replace the abc.zip/folder1/textfile.txt with the one inside seconddir/folder3/textfile.txt.
How do I achieve this via the command line interface?
I am trying to create a shell script where a user can specify a file with a list of logins and the script will create a batch file with specific information in specific columns.
Example:
loginfile.txt has
User1 User2 User3
I need the output to be as below:
1 User1 Date 12/31/9999 2 User2 Date 12/31/9999 3 User3 Date 12/31/9999
I can use the nl utility to get the numbers easily enough, but I need two tab separations between the number and the user list. Is there a sed command that will insert at the beginning of each line? If so I can just run nl after I get some tabs up in the front.
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 ?
i have two files with thousands of line, I am trying to combine these two files but i want to insert each line of one file to the another file after certain lines. I am using awk with the following command but it does not work.cat file1 | awk ' { print $0; if (NR%3004==0) {print "file2"}}' > outputfile
I need a shell script that will add the users name and date to a file when the user has modified the file, these files are within a group and only accessible to this group. But we need a way for people in the group to know who and when the file was last modified.
I am supposed to take some small files, and print them to a specific printer, such that the small files are concatenated into one file. The file name has to be included in the file that gets printed.
Should I be looking to concatenate the files into one file with the file names included, and then print them?
I've been reading tutorials of Linux sed command, but haven't got anything yet. the problem is : I want to insert a line into my DNS database file which has a pattern like below:
<Domain name> 3tabs here <IN> <A> <ip address>
the question is : how to add a line into a file like this using linux sed command? I have problem inserting tabs and the spaces!
is there a way that I can insert a wav file in an email and play when the receiver opens the mail? I don't mean when he clicks on an attachment but when he opens the message file. Using Latest Thunderbird version.
I want to insert graphics into latex file, for longtime I used xfig to create graphs, but it is limited,specially for math formulas, dia i find not easy to use.Finally I want to try asymptote or tikz which one is more appropriate
I would like to store JPG files in a mysql database table. I figured that using BLOB fields on the one hand and the 'load_file' command on the other would do the trick. Here is how I set up the table:
mysql> create table blobtable (id int(10) not null auto_increment, fileName varchar(15) not null, file longblob not null, primary key(id) ); Query OK, 0 rows affected (0.51 sec)
Then I tried to enter the data: mysql> insert into blobtable(filename,file)values('pic',load_file('/var/www/temp/IMGP4764.JPG'));
Which got me the following error signal: ERROR 1048 (23000): Column 'file' cannot be null
It seems to me that the file path to the JPG file (although correct) is the source of the problem, and is causing the load_file command not to work. My first attempt was with the JPG file in my PC's home directory. When that returned the same error message, I figured that maybe the file had to be in the PC's (server's) web area so I put it under the 'www' directory.
I want to read from the file and check for the pattern, if the line has some word like <string>: then string should be copied into buffer. Afterwards, I want to insert the same <string> with some word in the next line of the file. use sed command to perform the above mentioned operations?
I'm using Ubuntu minimal install (With no window manager). What is the quickest and easiest way to upload a file somewhere? Something like a script to pastebin would work.
I have a small script that uses the find command to look for a log file named: backup_log.txt. And then uses the first value in the log file as a variable in the script later on. However, say there are two or more of these log files located in different directories, how would I let the user choose which log file will be the one to use, and then make that (fullpathtofile) the value of the variable that will be used.
I am working on some homework, however i am not here to be spoon fed. I am trying to get the numerical modification date of each file in a folder. Ie lets say there is a file called bob and it was modified 2006-11-23. i want to get it into a variable as 20061123.
Now i currently have this code:
Code:
However for some reason my output is:
Quote:
See how the 2011 has been placed next to it? i ran it with -x and saw this:
Code:
However i do not know how to find a way around this?
Im looking to use the Apache2 GeoIP mod to block countries from accessing a website. I've searched, but cannot seem to find any information on how to insert the code into the virtual host file. Does anyone know how to get this working or can point me in the right direction?