Sponsored Content
Top Forums Shell Programming and Scripting How to use variables in 'sed' append command? Post 302756383 by Chubler_XL on Tuesday 15th of January 2013 07:29:38 PM
Old 01-15-2013
Put $c outside of single quotes:

Code:
#! /bin/bash
a=`grep -n "<name>abc</name>" file.txt` | awk '{print $1}'`
b=`echo ${a%?}`
c=`expr b+2`
sed $c'a\
\t<Property>\
\t\t<name>lmn</name>\
\t\t<value>90<\/value>\
\t<\/Property>' file.txt > file1.txt

This User Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

assigning variables in sed command

I need to assign a variable within a variable in a sed command. I tried doing the following in c shell. set left = 1 set right = 2 set segment = qwerty sed -n -e "/$segment{$left}/,/$segment{$right}/p" file.txt what is wrong with this syntax? (3 Replies)
Discussion started by: wxornot
3 Replies

2. UNIX for Dummies Questions & Answers

sed command not work with variables?

I am trying to write a simple script which will take a variable with sed to take a line out of a text and display it #!/bin/sh exec 3<list while read list<&3 do echo $list sed -n '$list p'<list2 done this does not work, yet when I replace the $list variable from the sed command and... (1 Reply)
Discussion started by: MaestroRage
1 Replies

3. Shell Programming and Scripting

What's wrong with this sed command? delete & append

I want to write a sed command that does the following work: file: <a>asdfasdf<\s> <line>hello</line> <b>adf<\c> <b>tttttttt<\c> output: name=hello sed -e 's/^*//' -n -e '/<line>/s/<*>//gp;' -e 's/^/name="/g' file but I can not append "=" after getting the line with... (5 Replies)
Discussion started by: minifish
5 Replies

4. Shell Programming and Scripting

Can i use Variables in sed command in line numbers

I wish to give line number from one point to another in sed command like this sed -n 1,1000000p file1.txt >file2.txt but variable line number $x,$x+100000 can i give it cos i tried and it was giving an error any suggestions?/ Thx in advance AC (2 Replies)
Discussion started by: bezudar
2 Replies

5. Shell Programming and Scripting

sed: command garbled - when executed with $variables

I have got a file job_tree.lst , which contains 1 line as below $ cat job_tree.lst ABC_D_EQ_XXXXX_YYYY_PRD_UX 05/08/2009 05:47 05/08/2009 05:50 IN 13412850/0 I want to get a child job string 3 characters offset from the parent job string (i.e. ABC_D_EQ_XXXXX_YYYY_PRD_UX 05/08/2009... (4 Replies)
Discussion started by: Armaan_S
4 Replies

6. Shell Programming and Scripting

Variables in SED command

Hi all, I want write a script to display 5rows at times from a input file. my out like: echo " display started" r1 r2 r3 r4 r5 ... Some action items... again i need next 5 lines. can you please advise. (2 Replies)
Discussion started by: koti_rama
2 Replies

7. Shell Programming and Scripting

How to append something to a word using sed command

Hi, How to append something to already existing word. Suppose, I have the following line as a part of a file. VVV= jdbc:... (6 Replies)
Discussion started by: Dpu
6 Replies

8. Shell Programming and Scripting

How to append a value to the output after using sed command?

Hi All, I have a file where I am converting newlines to comma separated values but I would like to append zero if the output is empty Here is the command I am using sed -n -e 'H;${x;s/\n/,/g;s/^,//;p;}' test1.txt test1.txt will have comma seperated values but sometimes this file can be... (6 Replies)
Discussion started by: rajeevm
6 Replies

9. Shell Programming and Scripting

sed command to append word at end of line

hello Team, I am looking for sed command or script which will append word at end of line. for example. I want to validate particular filesystem with mount |<filesystem name> command. if nodev parameter is not there then it should add in the fstab file with receptive to the filesystem. # mount... (8 Replies)
Discussion started by: ghpradeep
8 Replies

10. UNIX for Beginners Questions & Answers

Help using combining variables with sed command (RHEL 7)

Here is the whole script, very simple, but I am just learning ROK_NO=$1 RPT=/tmp/test sed -E '/^SELECT/ s/(.{23}).{8}/\1'"$ROK_NO"' /' $RPT echo $RPT When I run this I get $ bash rok.sh 2388085 : No such file or directory /tmp/test When I type the command in console, it works... (3 Replies)
Discussion started by: isey78
3 Replies
HFIND(1)						      General Commands Manual							  HFIND(1)

NAME
hfind - Lookup a hash value in a hash database SYNOPSIS
hfind [-i db_type ] [-f lookup_file ] [-eq] db_file [hashes] DESCRIPTION
hfind looks up hash values in a database using a binary search algorithm. This allows one to easily create a hash database and identify if a file is known or not. It works with the NIST National Software Reference Library (NSRL) and the output of 'md5sum'. Before the database can be used by 'hfind', an index file must be created with the '-i' option. This tool is needed for efficiency. Most text-based databases do not have fixed length entries and are sometimes not sorted. The hfind tool will create an index file that is sorted and has fixed-length entries. This allows for fast lookups using a binary search algorithm instead of a linear search such as 'grep'. ARGUMENTS
-i db_type Create an index file for the database. This step must be done before a lookup can be performed. The 'db_type' argument specifies the database type (i.e. nsrl-md5 or md5sum). See section below. -f lookup_file Specify the location of a file that contains one hash value per line. These hashes will be looked up in the database. -e Extended mode. Additional information besides just the name is printed. (Does not apply for all hash database types). -q Quick mode. Instead of displaying the corresponding information with the hash, just display 0 if the hash was not found and 1 if it was. If this flag is used, then only one hash can be given at a time. -V Display version db_file The location of the hash database file. [hashes] The hashes to lookup. If they are not supplied on the command line, STDIN is used. If index files exist for both SHA-1 and MD5 hashes, then both types of hashes can be given at runtime. INDEX FILE
hfind uses an index file to perform a binary search for a hash value. This is much faster than using 'grep', which will do a linear search. Before a hash database is used, a corresponding index file must be created. This is done with the '-i' option to hfind. The resulting index file will be named based on the database file name. The name will have the original name following by the hash type (sha1 or md5) followed by '.idx'. For example, creating an MD5 hash index of the NIST NSRL results in 'NSRLFile.txt-md5.idx' and the SHA-1 index results in 'NSRLFile.txt-sha1.idx'. The file has two columns. Each entry is sorted by the first column, which is the hash value. The second column has the byte offset of the corresponding entry in the original file. So, when a hash is found in the index, the offset is recorded and then 'hfind' seeks to the entry in the original database. The following input types are valid. For NSRL, 'nsrl-md5' and 'nsrl-sha1' can be used. The difference is which hash value the index is sorted by. The 'md5sum' value can also be used to sort and index "home made" databases. 'hfind' can take data in both common formats: MD5 (test.txt) = 76b1f4de1522c20b67acc132937cf82e and 76b1f4de1522c20b67acc132937cf82e test.txt EXAMPLES
To create an MD5 index file for NIST NSRL: # hfind -i nsrl-md5 /usr/local/hash/nsrl/NSRLFile.txt To lookup a value in the NSRL: # hfind /usr/local/hash/nsrl/NSRLFile.txt 76b1f4de1522c20b67acc132937cf82e 76b1f4de1522c20b67acc132937cf82e Hash Not Found You can even do both SHA-1 and MD5 if you want: # hfind -i nsrl-sha1 /usr/local/hash/nsrl/NSRLFile.txt # hfind /usr/local/hash/nsrl/NSRLFile.txt 76b1f4de1522c20b67acc132937cf82e 80001A80B3F1B80076B297CEE8805AAA04E1B5BA 76b1f4de1522c20b67acc132937cf82e Hash Not Found 80001A80B3F1B80076B297CEE8805AAA04E1B5BA thrdcore.cpp To make a database of critical binaries of a trusted system, use 'md5sum': # md5sum /bin/* /sbin/* /usr/bin/* /usr/bin/* /usr/local/bin/* /usr/local/sbin/* > system.md5 # hfind -i md5sum system.md5 To look entries up, the following will work: # hfind system.md5 76b1f4de1522c20b67acc132937cf82e 76b1f4de1522c20b67acc132937cf82e Hash Not Found or # md5sum -q /bin/* | hfind system.md5 928682269cd3edb1acdf9a7f7e606ff2 /bin/bash <...> or # md5sum -q /bin/* > bin.md5 # hfind -f bin.md5 system.md5 928682269cd3edb1acdf9a7f7e606ff2 /bin/bash <...> SEE ALSO
sorter(1) The NIST National Software Reference Library (NSRL) can be found at www.nsrl.nist.gov. LICENSE
Distributed under the Common Public License, found in the cpl1.0.txt file in the The Sleuth Kit licenses directory. AUTHOR
Brian Carrier <carrier at sleuthkit dot org> Send documentation updates to <doc-updates at sleuthkit dot org> HFIND(1)
All times are GMT -4. The time now is 04:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy