Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to insert a string and variable at specified position in command in bash? Post 303042140 by RudiC on Monday 16th of December 2019 09:41:39 AM
Old 12-16-2019
That desired command is different from the one in post #1. What exactly and finally do you need?



Why the detour using $id in lieu of using the file names in the directory immediately?

Last edited by RudiC; 12-16-2019 at 01:49 PM..
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to find a position and print some string in the next and same position

I need a script for... how to find a position of column data and print some string in the next line and same position position should find based on *HEADER8* in text for ex: ord123 abs 123 987HEADER89 test234 ord124 abc 124 987HEADER88 test235 ... (1 Reply)
Discussion started by: naveenkcl
1 Replies

2. Shell Programming and Scripting

search a line and insert string into specific at position

Hi, guys. I have one question: How can I search for a line with certain string in it and then insert a string into this line? For example: There is a file called shadow, the contents of it are below: ************************** ... yuanz:VIRADxMsadfDF/Q:0:0:50:7:::... (9 Replies)
Discussion started by: daikeyang
9 Replies

3. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

4. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

Insert charactera in 1st position of specific lines using vi editor or sed command

Dear all, i am having text file like below surya rama ranga laxman rajesh reddy i want add string (OK) before a text from line 3 to 5 the result will be surya rama OK ranga OK laxman OK rajesh reddy (1 Reply)
Discussion started by: suryanarayana
1 Replies

7. Shell Programming and Scripting

Need command or script to print all lines from 2nd position to last but one position

hi guys, i want command or script to display the content of file from 2nd position to last but one position of a file abcdefghdasdasdsd 123,345,678,345,323 434,656,656,656,656 678,878,878,989,545 4565656667,65656 i want to display the same above file without first and... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

8. Shell Programming and Scripting

Search for a string at a particular position and replace with blank based on position

Hi, I have a file with multiple lines(fixed width dat file). I want to search for '02' in the positions 45-46 and if available, in that lines, I need to replace value in position 359 with blank. As I am new to unix, I am not able to figure out how to do this. Can you please help me to achieve... (9 Replies)
Discussion started by: Pradhikshan
9 Replies

9. UNIX for Beginners Questions & Answers

Bash: Insert in a variable a file

hi all i have a problem in the bash shell. i'd like insert in a variable a file for example : i have a file datafine.log in this file there is : 17/JUN/2019 i want to insert the value of datafine.log in a variable. Regards Frncesco edit by bakunin: please use CODE-tags for your data... (2 Replies)
Discussion started by: Francesco_IT
2 Replies

10. UNIX for Beginners Questions & Answers

How to insert subnode in xml file using xmlstarlet or any other bash command?

I have multiple xml files where i want to update a subnode if the subnode project points to different project or insert a subnode if it doesn't exist using a xmlstarlet or any other command that can be used in a bash script. I have been able to update the subnode project if it doesn't point to... (1 Reply)
Discussion started by: Sekhar419
1 Replies
try(3tcllib)					   Forward compatibility implementation of [try]				      try(3tcllib)

__________________________________________________________________________________________________________________________________________________

NAME
try - try - Trap and process errors and exceptions SYNOPSIS
package require Tcl 8.5 package require try ?1? ::try body ?handler...? ?finally script? _________________________________________________________________ DESCRIPTION
This package provides a forward-compatibility implementation of Tcl 8.6's try/finally command (TIP 329), for Tcl 8.5. The code was directly pulled from Tcl 8.6 revision ?, when try/finally was implemented as Tcl procedure instead of in C. ::try body ?handler...? ?finally script? This command executes the script body and, depending on what the outcome of that script is (normal exit, error, or some other excep- tional result), runs a handler script to deal with the case. Once that has all happened, if the finally clause is present, the script it includes will be run and the result of the handler (or the body if no handler matched) is allowed to continue to propa- gate. Note that the finally clause is processed even if an error occurs and irrespective of which, if any, handler is used. The handler clauses are each expressed as several words, and must have one of the following forms: on code variableList script This clause matches if the evaluation of body completed with the exception code code. The code may be expressed as an integer or one of the following literal words: ok, error, return, break, or continue. Those literals correspond to the integers 0 through 4 respectively. trap pattern variableList script This clause matches if the evaluation of body resulted in an error and the prefix of the -errorcode from the interpreter's status dictionary is equal to the pattern. The number of prefix words taken from the -errorcode is equal to the list-length of pattern, and inter-word spaces are normalized in both the -errorcode and pattern before comparison. The variableList word in each handler is always interpreted as a list of variable names. If the first word of the list is present and non-empty, it names a variable into which the result of the evaluation of body (from the main try) will be placed; this will contain the human-readable form of any errors. If the second word of the list is present and non-empty, it names a variable into which the options dictionary of the interpreter at the moment of completion of execution of body will be placed. The script word of each handler is also always interpreted the same: as a Tcl script to evaluate if the clause is matched. If script is a literal - and the handler is not the last one, the script of the following handler is invoked instead (just like with the switch command). Note that handler clauses are matched against in order, and that the first matching one is always selected. At most one han- dler clause will selected. As a consequence, an on error will mask any subsequent trap in the try. Also note that on error is equivalent to trap {}. If an exception (i.e. any non-ok result) occurs during the evaluation of either the handler or the finally clause, the origi- nal exception's status dictionary will be added to the new exception's status dictionary under the -during key. EXAMPLES
Ensure that a file is closed no matter what: set f [open /some/file/name a] try { puts $f "some message" # ... } finally { close $f } Handle different reasons for a file to not be openable for reading: try { set f [open /some/file/name] } trap {POSIX EISDIR} {} { puts "failed to open /some/file/name: it's a directory" } trap {POSIX ENOENT} {} { puts "failed to open /some/file/name: it doesn't exist" } BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category try of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. SEE ALSO
catch(3tcl), error(3tcl), return(3tcl), throw(3tcl) KEYWORDS
cleanup, error, exception, final, resource management CATEGORY
Utility COPYRIGHT
Copyright (c) 2008 Donal K. Fellows, BSD licensed try 1 try(3tcllib)
All times are GMT -4. The time now is 04:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy