Read value of a file, remove first 2 chars and put this value in a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read value of a file, remove first 2 chars and put this value in a variable
# 1  
Old 07-05-2012
Read value of a file, remove first 2 chars and put this value in a variable

Hi i have need of read a file value with cat command and remove first 2character for example cat /sys/class/rtc/day

0x12

Remove char

12

And put this value in a variable

is possible with a script thanks for help
# 2  
Old 07-05-2012
Code:
read VAR < /sys/class/rtc/day
VAR=${VAR:2}

# 3  
Old 07-05-2012
Or

Code:
VAR=${VAR#??}

# 4  
Old 07-05-2012
Or
Code:
IFS=x read dummy VAR < /sys/class/rtc/day

# 5  
Old 07-06-2012
ok i try

---------- Post updated at 04:44 AM ---------- Previous update was at 02:56 AM ----------

i have a problem because i not have a file.
But i have a result of a command for example:

root@freescale ~$ i2cget -f -y 0 0x51 8
0x12

how can take this value?

thanks
# 6  
Old 07-06-2012
Code:
var=$(i2cget -f -y 0 0x51 8|cut -c 3-)

# 7  
Old 07-06-2012
PROBABLY cut -c 2- ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I must use first sentence from a file to put into variable

i am having some bash script which must use first sentence of the file. For example i have file which content is: test 213 So I must use word test into my bash script, and put it into variable. I am using a one variable named value value=$(</home/rusher/test.txt) so instead using test.txt... (1 Reply)
Discussion started by: tomislav91
1 Replies

2. Shell Programming and Scripting

Read file and get the data then put it in array

Hi, I have a file called "readfile" it contains below parameters #cat readfile word=/abc=225,/abc/cba=150 three=12 four=45 five=/xyz/yza likewise multiple line. From the above file, I have to read "word" output should be like, /abc /abc/cba these values need to be put in... (3 Replies)
Discussion started by: munna_dude
3 Replies

3. Shell Programming and Scripting

How to put content of file into a variable?

For example, I have a simple text file note: this a note a simple note a very very simple notewhen I use this command, temp=$(cat "note.txt")then I echo temp, the result is in one line. echo $temp note: this a note a simple note a very very simple noteMy variable doesn't have newline. How... (7 Replies)
Discussion started by: 14th
7 Replies

4. Shell Programming and Scripting

Read a file and put it in HTML format

Hi, I have one file as follows and I need to read this file contents in an HTML format. And send html file to some mail ids using sendmail. Communications Pvt Ltd Report AccountId Name Code IdBill Balance ... (3 Replies)
Discussion started by: Kattoor
3 Replies

5. Shell Programming and Scripting

remove first line from a file and put into another file

I want to remove first line from a file containing 10K + records and want to put that into a new file. Tried sed '1d' filename>newfile This is writing all the records into new file. Can somebody help please? (4 Replies)
Discussion started by: gpaulose
4 Replies

6. Shell Programming and Scripting

Read multiple log files and create output file and put the result

OS : Linux 2.6.9-67 - Red Hat Enterprise Linux ES release 4 Looking for a script that reads the following log files that gets generated everynight between 2 - 5am Master_App_20090717.log Master_App1_20090717.log Master_App2_20090717.log Master_App3_20090717.log... (2 Replies)
Discussion started by: aavam
2 Replies

7. Shell Programming and Scripting

read a file in shell and put result in a line

Hi All, I have a to read a file and put the result in one line. The i am reading from contain the data like below. 1 signifies the beging of the new line. (6 Replies)
Discussion started by: lottiem
6 Replies

8. Shell Programming and Scripting

remove newline chars in each record of file

Hi, I have a fixed width file with record length 10. I need to remove multiple newline characters present in each record. EX: af\n72/7\n s\n3\nad\n 2\n\n33r\n In the above file I want to remove new lines in red color(\n) but not (\n) Please provide me a solution. Thanks, Sri (1 Reply)
Discussion started by: srilaxmi
1 Replies

9. Shell Programming and Scripting

put the contents of this file into a variable with multiple lines

I have a file that contains the following lines the brown quick fox jumped over the white laze dog 0123456789 I wanted to put the contents of this file into a variable so I used this code: VAR_LIST=`cat $2` where $2 is the file name passed as an argument to the script If I... (3 Replies)
Discussion started by: Nomaad
3 Replies

10. AIX

Put one ligne from a file a variable

Hi everybody I looking the put the result of a commane to a Variable i explain here is my command: FJTS_UK:root:common@ukaix3:/> cat sortie | grep "^"| awk '{ print $1}' 15 FJTS_UK:root:common@ukaix3:/> sortie is a texte file I want to put the result of commande in a... (1 Reply)
Discussion started by: kykyboss
1 Replies
Login or Register to Ask a Question