Results 1 to 5 of 5
hi,
i have a file and within the file i have some text. I need to remove the following characters from the file. See my example below :
cat file1.dat
...
- 10-12-2011 #1Just Joined!
- Join Date
- Oct 2011
- Posts
- 12
sed issue
hi,
i have a file and within the file i have some text. I need to remove the following characters from the file. See my example below :
cat file1.dat
Initialize.txt R1_P1000_ABCD_CAL_20101231_Config1C.tar
and I would require the file to look like this (like to remove .tar) :
cat file1.dat
Initialize.txt R1_P1000_ABCD_CAL_20101231_Config1C
How can I do this using the SED command ?
thank you
- 10-12-2011 #2This will remove all ".tar".Code:
sed 's/\.tar//g' file1.dat
If the result is to your liking, add -i to the sed call and file1.dat will be changed in place.You must always face the curtain with a bow.
- 10-12-2011 #3Just Joined!
- Join Date
- Oct 2011
- Posts
- 12
That has worked ok, but if I add a tar command to the file1.dat, see below :
cat file1.dat
tar xvf R1_P1000_ABCD_CAL_20101231_Config1C.tar
Initialize.txt R1_P1000_ABCD_CAL_20101231_Config1C.tar
and I ran the sed command :
sed 's/\.tar//g' file1.dat
This removes the .tar from the 1st line, but I need to keep this line as the same.
Only the second line needs the .tar removed.
Please could you advise the best way for this.
thank you
- 10-12-2011 #4
To continue the way
But since you ask for the best way..Code:sed '2s/\(Initialize\.txt.*\)\.tar/\1/' file1.dat
The sed approach seems like fixing after the fact.
Maybe that file1.dat can be created correctly in the first place?
How is it generated?You must always face the curtain with a bow.
- 10-12-2011 #5Just Joined!
- Join Date
- Oct 2011
- Posts
- 12
thank you, I am now using your example within my script that i have created - see below :
#!/bin/sh
#set -x
################################################## ##############################
#
# Copyright ABC plc 2011
#
# Name: Verify_Install.sh
#
# Version: V0.1
# Date: 12-10-11
#
# Purpose: Verify Install Process
#
################################################## ##############################
#############################################
# Start Verify Intall Processes #
#############################################
Verify_Install()
{
SCRIPTS_DIR=$HOME/Control_Management/scripts
BUILD_DIR=$RELEASE/$CURRENT_CONFIG/Config
PROCESS_DIR=$RELEASE/Scripts/Batch
PACKAGE_CONFIG1C_DIR=$OPS/Project/Release1/Config1C/Dynamic
cd $PACKAGE_CONFIG1C_DIR
tar xvf R1_P1000_ABCD_CAL_20101231_Config1C.tar
cd $PROCESS_DIR
echo "Jobstream Verify_Install Started"
echo " "
./Initialize.ksh R1_P1000_ABCD_CAL_20101231_Config1C.tar 20101231
echo " "
echo "Jobstream Verify_Install completed"
}
now when i use your example, this still keeps the same format for both lines in my script.
The line - tar xvf R1_P1000_ABCD_CAL_20101231_Config1C.tar needs to stay the same
and the following line - ./Initialize.ksh R1_P1000_ABCD_CAL_20101231_Config1C.tar 20101231
needs the .tar removed from this line only.
kind regards


Reply With Quote